C ++ shared object

Hi

I have the following code:

class Libr
{   

public:
Libr();
std::string book;

class Street
{
public:
Street();

}*street
}*libr;

How to use a shared object in the following method:

void find(std::string, ??generic object)
{//code};

Can someone please give me an example with a common object applied to both classes that I wrote? thank!

+3
source share
2 answers

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 about templates.

+3
source

Or you can pass an untyped pointer:

void find(std::string, void* object)
{
    //code
}

It depends on what you are going to do inside find ().

+1
source

All Articles