template
class SimpleTemplate
{
public:
SimpleTemplate(T &inObject);
const T& get();
void set(T& inObject);
protected:
T& mObject;
};
template
SimpleTemplate::SimpleTemplate(T &inObject) : mObject(inObject)
{
}
template
const T& SimpleTemplate::get()
{
return mObject;
}
template
void SimpleTemplate::set(T& inObject)
{
mObject = inObject;
}
#include
#include
using namespace std;
int main(int argc, char** argv)
{
int i = 7;
SimpleTemplate intWrapper(i);
i = 2;
cout << "wrapper value is " << intWrapper.get() << endl;
string str = "test";
SimpleTemplate stringWrapper(str);
str += "!";
cout << "wrapper value is " << stringWrapper.get() << endl;
}