linuxx linuxx - 1 year ago 106
C++ Question

c++ generic object


I have the following code:

class Libr

std::string book;

class Street


How can I use a generic object in the following method:

void find(std::string, ??generic object)

Can someone please give me an example with the generic object applied for both the classes I wrote?THX!

Answer Source

You can make it a function template:

template<class T>
void find(std::string s, T & object)

You can call this with a parameter of any type. Read this to get more on templates.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download