Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > gcc 4 can not resolve member var derived from base class in atemplate class

Reply
Thread Tools

gcc 4 can not resolve member var derived from base class in atemplate class

 
 
steve yee
Guest
Posts: n/a
 
      07-01-2008
#include <iostream>
#include <list>

template<class mt_policy>
class Base
{
public:
int a;
};

template<class mt_policy = int>
class signal0 : public Base<mt_policy>
{
public:
void aaa()
{
std::cout<<"a = "<<a<<std::endl;
}
};

int main()
{
signal0<int> p;
p.aaa();
}
~

test.cpp: In member function ‘void signal0<mt_policy>::aaa()’:
test.cpp:17: error: ‘a’ was not declared in this scope
 
Reply With Quote
 
 
 
 
acehreli@gmail.com
Guest
Posts: n/a
 
      07-01-2008
On Jul 1, 9:05 am, steve yee <(E-Mail Removed)> wrote:
> #include <iostream>
> #include <list>
>
> template<class mt_policy>
> class Base
> {
> public:
> int a;
>
> };
>
> template<class mt_policy = int>
> class signal0 : public Base<mt_policy>
> {
> public:
> void aaa()
> {
> std::cout<<"a = "<<a<<std::endl;


This is the definition of class template signal0, not an instantiation
of it. So the compiler cannot know whether any Base<mt_policy> will
provide an 'a'. For example, some specialization may not have an a.

The compiler cannot assume that a missing name will be available
through a templated base. What if there were two bases?

The solution is to fully qualify 'a': Base<mt_policy>::a

> }
>
> };
>
> int main()
> {
> signal0<int> p;
> p.aaa();}
>
> ~
>
> test.cpp: In member function ‘void signal0<mt_policy>::aaa()’:
> test.cpp:17: error: ‘a’ was not declared in this scope


Ali
 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      07-01-2008
steve yee wrote:
> test.cpp: In member function ‘void signal0<mt_policy>::aaa()’:
> test.cpp:17: error: ‘a’ was not declared in this scope


You have to add this to your signal0 class:

using Base<mt_policy>::a;

I don't remember now why this was standardized like that.
 
Reply With Quote
 
steve yee
Guest
Posts: n/a
 
      07-01-2008

so this is a standard, not a bug of gcc? but vc9 can compile it.


On Jul 2, 2:00*am, Juha Nieminen <(E-Mail Removed)> wrote:
> steve yee wrote:
> > test.cpp: In member function ‘void signal0<mt_policy>::aaa()’:
> > test.cpp:17: error: ‘a’ was not declared in this scope

>
> * You have to add this to your signal0 class:
>
> using Base<mt_policy>::a;
>
> * I don't remember now why this was standardized like that.


 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      07-01-2008
steve yee wrote:
> so this is a standard, not a bug of gcc? but vc9 can compile it.


VC9 doesn't obey the standard in all respects.
 
Reply With Quote
 
Bo Persson
Guest
Posts: n/a
 
      07-01-2008
Juha Nieminen wrote:
> steve yee wrote:
>> so this is a standard, not a bug of gcc? but vc9 can compile it.

>
> VC9 doesn't obey the standard in all respects.


It does respect this, if you ask it too (option /Za). Default is to
compile old, pre-standard, Windows code.


Bo Persson


 
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
Derived::Derived(const Base&) and Derived& operator=(const Base&) developereo@hotmail.com C++ 1 05-23-2007 01:44 PM
Derived::Derived(const Base&) and Derived& operator=(const Base&) developereo@hotmail.com C++ 1 05-23-2007 12:07 AM
derived class and base class, member assignment, which goes first user C++ 1 07-11-2005 04:25 AM
When is a base class protected member not visible in a derived class? Andy Lomax C++ 5 06-30-2005 04:34 AM
Can Derived class static member access protected member from base class? Siemel Naran C++ 4 01-12-2005 06:46 PM



Advertisments