Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > template class

Reply
Thread Tools

template class

 
 
Qian Xin
Guest
Posts: n/a
 
      05-14-2011
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;
}
 
Reply With Quote
 
 
 
 
Qian Xin
Guest
Posts: n/a
 
      05-14-2011
On May 14, 7:44*pm, Qian Xin <(E-Mail Removed)> wrote:
> 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/arc...11/212768.aspx
 
Reply With Quote
 
 
 
 
Johannes Schaub
Guest
Posts: n/a
 
      05-15-2011
Qian Xin wrote:

> 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/5...d-typename-in-
templates/5581807#5581807
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      05-15-2011
Qian Xin <(E-Mail Removed)> wrote:
> any one can give a reason


The standard says so.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring a template class with two template params a friend in anon-template class A L C++ 1 08-25-2010 07:25 AM
r H2 deduce deduce template argument of a template class inheritingfrom a non template base? nguillot C++ 5 03-08-2009 05:56 PM
How to use the template member function of a template in the memberfunction of another template class? Peng Yu C++ 3 10-26-2008 03:51 PM
template template arguments: expected a class template, got `Component<T1, T2, T3> gary.bernstein@gmail.com C++ 1 06-08-2007 07:10 AM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM



Advertisments