[Cpp-Programming] Re: Template problem, data member undefined!!!
In the first case, the compilation would fail.
I used gcc 3.4.4 (cygwin) and gcc 4.2.4 (ubuntu)
to compile the code
Here the the error message:
error: 'numArray' was not declared in this scope
On Feb 16, 1:35 am, Ramaraju naga <v.nagaramar...@gmail.com> wrote:
> It is working either case...friend
>
> what was the problem...
>
> Thanks & Regards
> Ramaraju
>
> On Mon, Feb 16, 2009 at 11:51 AM, SeaN <guo.xiaoy...@gmail.com> wrote:
>
> > Please take a look at the following code,
> > my question is: why I have to use
> > Base<_Tp>::datamember to refer the datamember
> > in the base class in the derived class?
> > When I use datamember in the derived class,
> > the compilation would fail.
>
> > I use gcc 3.4.4 (cygwin)
>
> > #include <iostream>
>
> > template <typename _Tp>
> > class Base
> > {
> > protected:
> > _Tp numArray[3];
> > Base()
> > {
> > numArray[0] = static_cast<_Tp>(1);
> > numArray[1] = static_cast<_Tp>(11);
> > numArray[2] = static_cast<_Tp>(111);
> > };
> > };
>
> > template <typename _Tp>
> > class Deriv: public Base<_Tp> {
> > public:
> > Deriv() {
>
> > /* Why the following commented code can not be successfully
> > compiled?
> > * I got the numArray undefined error !!
> > *
> > std::cout << numArray[0] << std::endl;
> > std::cout << numArray[1] << std::endl;
> > std::cout << numArray[2] << std::endl;
> > */
>
> > /* correct code */
> > std::cout << Base<_Tp>::numArray[0] << std::endl;
> > std::cout << Base<_Tp>::numArray[1] << std::endl;
> > std::cout << Base<_Tp>::numArray[2] << std::endl;
> > };
> > };
>
> > int main(void)
> > {
> > Deriv<int> de;
>
> > return 0;
> > }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C++ Programming" group.
To post to this group, send email to Cpp-Programming@googlegroups.com
To unsubscribe from this group, send email to Cpp-Programming+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Cpp-Programming?hl=en
-~----------~----~----~----~------~----~------~--~---
0 Comments:
Post a Comment
<< Home