using another class's public member functions 
Author Message
 using another class's public member functions

What is the most straight-forward way for a class to make use of another
class's public member functions?  I thought it was enough to have declared
the function public and then say Class::Function() from a function in
another class, but apparently there's more to it than that.

Thanks for your help!



Mon, 10 Jun 2002 03:00:00 GMT  
 using another class's public member functions


Quote:
> What is the most straight-forward way for a class to make use of another
> class's public member functions?  I thought it was enough to have declared
> the function public and then say Class::Function() from a function in
> another class, but apparently there's more to it than that.

That only works for static member functions. If the function is non-static,
you need to call it through an instance of the class.

If this does not make sense, you need to learn more about basic C++. If you
understand this and something still isn't working, please post a short
example of the problem and be specific as to the error.

--
Barry L. Wallis, Senior Systems Engineer
Science Applications International Corporation
4161 Campus Point Court
San Diego, CA 92121



Mon, 10 Jun 2002 03:00:00 GMT  
 using another class's public member functions
To be more complete, what the other poster was trying to say was that you
need to do this:

Class MyClass;
MyClass.Function();

If you want to allocate space for your instance at run-time instead of
compile-time, do this:

Class* pClass;
pClass = new Class;
pClass->Function();
delete pClass;

If you need more language help, you can send e-mail.


Quote:
> What is the most straight-forward way for a class to make use of another
> class's public member functions?  I thought it was enough to have declared
> the function public and then say Class::Function() from a function in
> another class, but apparently there's more to it than that.

> Thanks for your help!



Tue, 18 Jun 2002 03:00:00 GMT  
 using another class's public member functions


Quote:
> To be more complete, what the other poster was trying to say was that you
> need to do this:

> Class MyClass;
> MyClass.Function();

> If you want to allocate space for your instance at run-time instead of
> compile-time, do this:

> Class* pClass;
> pClass = new Class;
> pClass->Function();
> delete pClass;

> If you need more language help, you can send e-mail.



> > What is the most straight-forward way for a class to make use of another
> > class's public member functions?  I thought it was enough to have
declared
> > the function public and then say Class::Function() from a function in
> > another class, but apparently there's more to it than that.

> > Thanks for your help!



Fri, 21 Jun 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Function pointer to a public member of the same class

2. Using class member function as a thread function

3. Using class member function as a thread function

4. class view dosen't shows member variable's and functions defined with macros

5. can't invoke template class member function

6. Calling another class's member function from OnReceive

7. exporting template class' member functions from dll

8. Using member function templates in template class under VC++ 5.0

9. Public static members in abstract base classes?

10. Calling public member fcns of main classes.

11. Getting access to a public member in a child class

12. Calling public member fcns of main classes.

 

 
Powered by phpBB® Forum Software