I use this C++ code for storing x to the variable val.
class Hello
{
int val;
public:
Hello(int x) : val(x) {}
};
However, when I saw this code, I cannot see how Super can store value t or o.
template<typename T>
class K : public std::auto_ptr<T>
{
typedef std::auto_ptr<T> Super;
public:
K() : Super() { }
K(T* t) : Super(t) { }
K(K<T>& o) : Super(o) { }
};
How does this code work?
Could’ve been written as
Which is just more verbose to initialize the base class. A typedef is cleaner most of the time if you have to deal with templated base classes.