Accessing protected members of template base class

I have a problem with template class inheritance. I have a base template class and a deriving class from the base class. I can not access the protected member of the base class in the derived class constructor. It gives that error:

prg.cpp: In constructor ‘ThresholdPrerequirement<T>::ThresholdPrerequirement(int)’:
prg.cpp:88: error: ‘_size’ was not declared in this scope


When I change the template classes to normal classes, then I can access the protected member with no problem.
What's wrong with this code?
Thanks.

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
template <typename T>
class SizePrerequirement
{
        public:
                SizePrerequirement():
                        _size(0)
        {
        }
                SizePrerequirement(int sz):
                        _size(sz)
        {
        }
        protected:
                int _size;
        private:
};
template <typename T>
class ThresholdPrerequirement:public SizePrerequirement<T>
{
        public:
                ThresholdPrerequirement(int sz):
                        SizePrerequirement<T>(sz)
                {
                        _size = 0; // <----------THIS LINE GIVES COMPILE ERROR!
                }
        protected:
        private:
};


You might want to try:
this->_size = 0;
Last edited on
Code works fine with me. What compiler are you using?
magnificence7:

you are using a non-standard compiler; the above code is not legal syntax.

The correct line is:

 
SizePrerequirement<T>::_size = 0;


magnificence, I use g++ 4.4.2
js.mith, yes it solved the problem.
Thanks
Topic archived. No new replies allowed.