My topic question is a little misleading, I dont want to implement a whole class like a std::ve开发者_Python百科ctor but I want to be able to create a class called Container so I can declare it like so:
Container <unsigned int> c;
So is this how I overload the <> operator...
class Container
{
private:
Container()
{
...
}
public:
void operator <>( unsigned int )
{
// what do I put here in the code?
// maybe I call the private constructor...
Container();
}
};
There is no operator <>
. The <>
denotes that Container
is a class template. You need syntax along the lines of:
template <typename T>
class Container
{
...
};
The best place to start is to find a good C++ book, but you could also try reading e.g. the C++ FAQ page about templates.
You should learn more about templates.
http://www.cplusplus.com/doc/tutorial/templates/
In a nutshell, what you want is:
template <class T>
class Container {
....
};
精彩评论