Error when porting c++ code from hp-ux to linux

Need help with C, C++, perl, python, etc?

Error when porting c++ code from hp-ux to linux

Postby oliver67 » 2007-01-12 08:32

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.

Does anyone, why?

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;
}
oliver67
 
Posts: 10
Joined: 2007-01-12 07:38

Postby neowolf » 2007-01-13 15:59

Hmm, why are you using g++ to compile what looks like a C program? that would done with `gcc sample.c -o sample-bin`. Anyway, I would imagine that this is a problem with the code itself not the os, perhaps there is an error in the scopes permissible to gcc 3.0.x but not to gcc 3.4.x
neowolf
 
Posts: 9
Joined: 2007-01-07 13:31

Postby pepribal » 2007-01-13 18:48

I seriously doubt that gcc accepts templates, classes and namespace handling :roll: :wink:

I have compiled it using g++ version 3.3.5 and it accepts it. I really can't see why it isn't accepting a reference to c1i, as C2 should inherit this member publicly.

(by the way, I think you don't need to write the "using" sentence, as you are #including the header files in the standard-C way)
pepribal
 
Posts: 5
Joined: 2006-10-22 17:54

Postby bzr » 2007-01-16 09:26

Try replacing
Code: Select all
T PROC(T x) { c1i = c2i; };

with:
Code: Select all
T PROC(T x) { C1<T>::c1i = c2i; };
bzr
 
Posts: 1
Joined: 2007-01-16 09:00


Return to Programming

Who is online

Users browsing this forum: No registered users and 10 guests

fashionable