Hi (English is not my first language, please understand me even if I make mistakes! thank you!!)
I'm writing a template class that can contain a pointer.
template <typename T>
class SmartPtr {
private:
T value;
public:
SmartPtr() {};
~SmartPtr() {};
SmartPtr(T* a)
{
this->value = *a;
}
SmartPtr(SmartPtr* a)
{
this->value = a->get_Value();
}
SmartPtr(SmartPtr const* a)
{
this->value = a->get_Value();
}
T get_Value()const{
return this->value;
}
};
This is template class called SmartPtr, and
class Test
{
public:
Test() { std::cout << "Test::Test()" << std::endl; }
Test(Test const&) { std::cout << "Test::Test(Test const&)" << std::endl; }
~Test() { std::cout << "Test::~Test()" << std::endl; }
Test& operator=(Test const&)
{
std::cout << "Test& Test::operator=(Test const&)" << std::endl;
return *this;
}
void print() const { std::cout << "Test::print() const" << std::endl; }
void print() { std::cout << "Test::print()" << std::endl; }
};
this is my Test class.
When I declare
SmartPtr<Test> ptr_t1 = SmartPtr<Test>(new Test);
in my main.cpp,
the result after compiling is
Test::Test()
Test::Test()
Test& Test::operator=(Test const&)
Test::~Test()
but the result that I want to get is
Test::Test()
Test::~Test()
Is there a specific template class copy contructor that I need to write in this situation?
Thank you so much for your patience!