# include <memory>
# include <string>
class Test
{
public:
Test(std::string _value);
Test(const Test& test);
Test& operator = (const Test& that);
~Test(){};
void setValue(std::string _value) { value = _value; };
void setInt(int _value){ i = _value; };
private:
std::string value;
int i = 10;
};
Test::Test(std::string _value)
{
value = _value;
}
Test::Test(const Test& test)
{
value = test.value;
i = test.i;
}
Test& Test::operator=(const Test& that)
{
value = that.value;
i = that.i;
return *this;
};
void doit(const Test& value);
void doita(const std::unique_ptr<Test>& value);
int _tmain(int argc, _TCHAR* argv[])
{
std::shared_ptr<Test> aa(new Test("TEST"));
aa->setInt(20);
doit(*aa.get());
//doita(aa)
return 0;
}
void doit(const Test& value)
{
//i want a copy of value that does not change original
std::unique_ptr<Test> b(new Test(value));
b->setInt(10);
}
void doita(const std::unique_ptr<Test>& value)
{
//i want a copy of value that does not change original
value.get()->setInt(10);
}