Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function that can take anything as a parameter? 2

Status
Not open for further replies.

Wings

Programmer
Feb 14, 2002
247
0
0
US
Hello, I know it is possible, but I cant remember how to do it. I need to make a function that can take any object as a parameter. I think I use the CObject class but I could be wrong. Can anyone point me in the right direction.

Thanks
 
I think it's too abstract question.
can take any object as a parameter? Object of what hierarchy? No any super object (Adam or Eve in the Object Universe;). It's Java (wrong designed;) Object superclass, but we are on (MS) C++ forum (don't you?)...

The only way to accept a pointer to any object is:
Code:
Type f(const void*);
But it's a totally useless interface (IMHO;)...
 
I want to take an object and an enumerated type as perameters. Based on the enumerated type, I want to cast the object to a particular type. Is it possible to do this with a CObject?
 
In general you can't cast an object of one class to another class (with or without CObject). So explain, please, your true problem.
In MFC environment you derive the class from the CObject if you need CObject functionality (serialization, for example). Then you may pass CObject pointer or reference to the derived class object and use it in a function as a polymorphic (CObject type) object via virtual functions. You don't cast it, you use it as a CObject object.
What else?
Can you present minimal pseudocode snippet with desired ops on your generic argument?
 
I guess I was thinking you could do something you cant. The best route to go is probably just to use overloaded functions. Thanks for the help.
 
Code:
template <class T>
T MyFunction( T  arg )
{
    // Do something with arg...

    return arg;
}
 
Slight correction: [tt]any[/tt] is a plain class, not a class template.
 
I cut someone's raise recently when i came across code like that haha... (determining the type of a pointer's target by consulting another argument)
 
This is an ancient thread. Please try not to resurrect dead discussions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top