Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   template class (http://www.velocityreviews.com/forums/t748285-template-class.html)

Qian Xin 05-14-2011 11:44 PM

template class
 
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;
}

Qian Xin 05-14-2011 11:47 PM

Re: template class
 
On May 14, 7:44*pm, Qian Xin <chians...@gmail.com> 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

Johannes Schaub 05-15-2011 12:04 AM

Re: template class
 
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

Juha Nieminen 05-15-2011 07:41 AM

Re: template class
 
Qian Xin <chianshin@gmail.com> wrote:
> any one can give a reason


The standard says so.


All times are GMT. The time now is 05:34 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57