error when porting from g++ for hp-ux to g++ for linux

Puetz, Oliver P11M22 Puetz.Oliver@siemens.com
Fri Jan 12 15:31:00 GMT 2007


Hi, 

here's a little sample code, which could be compiled with g++ 3.01 under
hp-ux, but when compiled with g++ 3.4.6 under linux, following error
occured: 

sample.c: In member function 'T C2<T>::PROC(T)': 
sample.c:19: error: 'c1i' was not declared in this scope 

Compilation was executed with "g++ sample.c" without any further
options. Other compiler versions are not existing. 

I sent this e-mail previously to gcc@gcc.gnu.org. There I got two hints:
  1. use this forum
  2. write this->c1i instead of c1i, which works.

But as this is a sample of a very large code, I will have to insert the
this->... many times. Does anyone knows another fix (maybe by gcc
options) ?

Many thanks in advance 

Oliver 


sample.c 
---------- 
#include <stdarg.h> 
#include <stdlib.h> 
#include <stdio.h> 

using namespace std; 

template <typename T> class C1 { 
public: 
T c1i; 
C1() { c1i = 1.0; }; 
~C1() { }; 
}; 

template <typename T> class C2 : public C1<T> { 
public: 
T c2i; 
C2() { c2i = 1; }; 
~C2() { }; 
T PROC(T x) { c1i = c2i; }; 
}; 

int main(int argc, char **argv) 
{ 
C1<double> c1; 
C2<double> c2; 

return EXIT_SUCCESS; 
}



More information about the Gcc-help mailing list