Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

class question

Posted on 1998-10-18
24
Medium Priority
?
193 Views
Last Modified: 2010-04-02
I have two classes the first has some functions.
the second class needs to use those functions
how can I do this.
HELP!!!
0
Comment
Question by:strmtrpr
  • 8
  • 5
  • 2
  • +7
24 Comments
 
LVL 5

Expert Comment

by:scrapdog
ID: 1175476
Declare the functions as public or make the 2nd class a descendent of the 1st class.
0
 

Author Comment

by:strmtrpr
ID: 1175477
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
 

Author Comment

by:strmtrpr
ID: 1175478
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Expert Comment

by:jbalagop
ID: 1175479
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
 
LVL 22

Expert Comment

by:nietod
ID: 1175480
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
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1175481
Well said, both of you!
0
 

Author Comment

by:strmtrpr
ID: 1175482
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
 
LVL 4

Expert Comment

by:pagladasu
ID: 1175483
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
 
LVL 1

Expert Comment

by:billyh
ID: 1175484
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
 
LVL 22

Expert Comment

by:nietod
ID: 1175485
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
 

Author Comment

by:strmtrpr
ID: 1175486
I am waiting for  jbalagop to answer so he can get the points
sorry billyh's
0
 

Expert Comment

by:xu092098
ID: 1175487
Maybe you can try declaring the second class as the friend of the first class.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175488
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
 

Author Comment

by:strmtrpr
ID: 1175489
the question has already been answered
Thanks anyway
0
 

Expert Comment

by:canoguz
ID: 1175490
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
 
LVL 5

Expert Comment

by:scrapdog
ID: 1175491
This is kind of funny.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175492
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
 
LVL 22

Expert Comment

by:nietod
ID: 1175493
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
 

Author Comment

by:strmtrpr
ID: 1175494
I wish there was a way just to give jbalagop the points.

0
 
LVL 7

Expert Comment

by:linda101698
ID: 1175495
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
 

Author Comment

by:strmtrpr
ID: 1175496
That is the truth
Thanks Linda
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1175497
haha. This was pretty funny. :-)
0
 

Accepted Solution

by:
jbalagop earned 200 total points
ID: 1175498
sorry for the delay i didn;t log on for a couple of days. i thank everyone who waited.
0
 

Author Comment

by:strmtrpr
ID: 1175499
Thanks Again for the help
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question