template class

Q

Qian Xin

template<typename T>
class TestCase: public MyClass
{
public:

int stringLength;
vector<T> String;
vector<T>::iterator i;
}

why the above cannot be compiled, gcc reporting the error:
xx.h:53: error: type ‘std::vector<T, std::allocator<_CharT> >’ is not
derived from type ‘TestCase<T>’
xx.h:53: error: expected ‘;’ before ‘i’

But the following can be compiled, any one can give a reason or
reference?

class TestCase: public MyClass
{
public:

int stringLength;
vector<T> String;
typename vector<T>::iterator i;
}
 
Q

Qian Xin

template<typename T>
class TestCase: public MyClass
{
public:

    int stringLength;
    vector<T> String;
    vector<T>::iterator i;

}

why the above cannot be compiled, gcc reporting the error:
xx.h:53: error: type ‘std::vector<T, std::allocator<_CharT> >’ is not
derived from type ‘TestCase<T>’
xx.h:53: error: expected ‘;’ before ‘i’

But the following can be compiled, any one can give a reason or
reference?

class TestCase: public MyClass
{
public:

    int stringLength;
    vector<T> String;
    typename vector<T>::iterator i;







}

sorry, I have found the answer:
http://blogs.msdn.com/b/slippman/archive/2004/08/11/212768.aspx
 
J

Johannes Schaub

Qian said:
template<typename T>
class TestCase: public MyClass
{
public:

int stringLength;
vector<T> String;
vector<T>::iterator i;
}

why the above cannot be compiled, gcc reporting the error:
xx.h:53: error: type ‘std::vector<T, std::allocator<_CharT> >’ is not
derived from type ‘TestCase<T>’
xx.h:53: error: expected ‘;’ before ‘i’

But the following can be compiled, any one can give a reason or
reference?

class TestCase: public MyClass
{
public:

int stringLength;
vector<T> String;
typename vector<T>::iterator i;
}

See http://stackoverflow.com/questions/5577950/keyword-typename-in-
templates/5581807#5581807
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top