• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

class question

I have two classes the first has some functions.
the second class needs to use those functions
how can I do this.
HELP!!!
0
strmtrpr
Asked:
strmtrpr
  • 8
  • 5
  • 2
  • +7
1 Solution
 
scrapdogCommented:
Declare the functions as public or make the 2nd class a descendent of the 1st class.
0
 
strmtrprAuthor Commented:
In the second class I have to write a function that uses the first classes functions.
I have declared the functions as public already.
the second class has private member ---      flower** ptr   // flower is the name of the first class.


0
 
strmtrprAuthor Commented:
In the second class I have to write a function that uses the first classes functions.
I have declared the functions as public already.
the second class has private member ---      flower** ptr   // flower is the name of the first class.


0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
jbalagopCommented:
to be able to call public functions of another class

class flower{
 public:
    func1()
}

class two{
 private:
    flower* ptr;
 voif func(){
    ptr = new flower; // <-- creating a flower object
    ptr->func1(); // <-- accessing the flower's class's public
                         function
 }

}

however, if you want to use flower** ptr instead
then: (*ptr) = new flower;
      (*ptr)->func1();


0
 
nietodCommented:
jbalagop,

This time you are not guessing.  (Well you almost are because strmtrpr is not providing any details, but it seems we have just enough details.)  It would not have been inappropriate to answer on the last comment.  

There is a fine line between beign to greedy and answering before you know you have really provided the answer and being to honerable and not answering until yoiu get confirmation.  The problem is that if you don't answer there is a good chance someone will come along and submit your idea as an answer.  This is unethical, but a few do it.  In many cases, the client realizes that they don't deserve the points, and rejects their answer so you can submit.  But not always.  So if you can answer, do.

todd
0
 
thresher_sharkCommented:
Well said, both of you!
0
 
strmtrprAuthor Commented:
jbalagop,  
 answer the question and I will give the points,
Thanks for the help. I still don't know why I over look the simple stuff.
THANKS.
0
 
pagladasuCommented:
Without going into debates on ethics, I have a suggestion. Why don't you make the first class a friend of the second one.
0
 
billyhCommented:
I have suggestion to your problem; make the second class a sub-class of the first one as follows:

class two: public flower
{
   private:
      ......//all your data members
   public:
      ......//overides or additional methods to the first class.
}

By doing this, the second class has access to both data members and functions of the first class and can still have other methods not known to the first class. You can also read more on any C++ book about Inheritance.

Hope this helps.
0
 
nietodCommented:
Billh, please read the question history.  That solution was already proposed by jbalagop (as well as others).  strmtrpr, has a working solution from what jbalagop proposed and has asked that jbalagop submit an answer.
0
 
strmtrprAuthor Commented:
I am waiting for  jbalagop to answer so he can get the points
sorry billyh's
0
 
xu092098Commented:
Maybe you can try declaring the second class as the friend of the first class.
0
 
nietodCommented:
xu, please read the question history.  That idea was proposed twice already.  strmfrpr, has a working solution.  he had opened the question so that jbalagop can answer.  Now jbalagop cannot answer.
0
 
strmtrprAuthor Commented:
the question has already been answered
Thanks anyway
0
 
canoguzCommented:
There are a few ways to do this :

 - If you want, you can inherit the second one from the first
 - You can declare the second one as a friend class to the first
 - You can declare them as static functions.
   ( Note : this may violate your class structure)
 
0
 
scrapdogCommented:
This is kind of funny.
0
 
nietodCommented:
I think this has become an expert IQ test--most are failing.

canoquz, read the question history from the beginning to the end before you answer.
0
 
nietodCommented:
I think jbalagop may have forgotten to mark the e-mail notification box for this question and that is why he is not responding.    I asked that customer service try e-mailing him directly concerning this.   In the meant time.

THIS QUESTION HAS BEEN ANSWERED.  WE ARE WAITING FOR JBALAGOP TO SUBMIT ANSWER.   NO ONE ELSE SHOULD ANSWER IT!!!!!!!!!!!!!!!!!!!!
0
 
strmtrprAuthor Commented:
I wish there was a way just to give jbalagop the points.

0
 
linda101698Commented:
I sent an email to jbalagop to post an answe to this question.  It is amazing how many experts don't read through the question before posting an answer.

Linda Gardner
Customer Service @ Experts Exchange
0
 
strmtrprAuthor Commented:
That is the truth
Thanks Linda
0
 
thresher_sharkCommented:
haha. This was pretty funny. :-)
0
 
jbalagopCommented:
sorry for the delay i didn;t log on for a couple of days. i thank everyone who waited.
0
 
strmtrprAuthor Commented:
Thanks Again for the help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 5
  • 2
  • +7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now