I have developed a container to hold some special kind of object (eg
Complex, Real and Integer objects, they are all derived from a object
named Number). See the example
class MyContainer
{
.
.
.
public:
// constructors
MyContainer(Number obj) { ... };
}
After that, I have seen the book <<Thinking in C++>>. In that book,
the author strongly recommend using the template. The code mentioned
above become
template <class T>;
class MyContainer
{
.
.
.
public:
// constructors
MyContainer(T obj) { ... };
}
The author says that the second approach is better than the first one. I don't
know why?
If I choose to use the template, how can I verify the type of the
class, I only want some class derived from Number exist in the
container. How can I do the identification of class in runtime?
Thanks in advance.

New Topic/Question
Reply




MultiQuote



|