Solved

class question

Posted on 1998-10-18
24
183 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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 50 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now