HI开发者_Go百科,
I have the following code:
class Libr
{
public:
Libr();
std::string book;
class Street
{
public:
Street();
}*street
}*libr;
How can I use a generic object in the following method:
void find(std::string, ??generic object)
{//code};
Can someone please give me an example with the generic object applied for both the classes I wrote?THX!
You can make it a function template:
template<class T>
void find(std::string s, T & object)
{
//code
};
You can call this with a parameter of any type. Read this to get more on templates.
Or you can pass untyped pointer:
void find(std::string, void* object)
{
//code
}
It depends on what you are going to do inside find().
精彩评论