Afficher un message
Vieux 17/10/2007, 12h17   #1
Thomas.Zauner@icp.uni-stuttgart.de
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut template+inheritance and old code


Hi,

i have to get an aprx. 9 year old code running. back then id did
compile but now it doesn't.
i have broken down the problem to the following technique which is
used quit freq. in the code.
don't ask me why it was used or if it makes sense, i don't even know
the guy who wrote it personally.

If you have any information about:

a) why this is not working anymore.
b) when did this stop working
c) can i use a compiler switch to accept the code (will it run?)


BTW: i work under linux using gcc and/or the intel c++ compiler

would be so much appreciated .-)

--------------------------------------------------------------------------------------------
#include <iostream>

using namespace std;

template<class T,int dim>
class TBase
{
public:
TBase(T val){pvar[dim-1]=val;};
T show_B(void){ return pvar[dim-1];};
protected:
T pvar[dim];
};

template <class TC>
class TClass: public TBase<TC,1>
{
public:
TClass(TC bval):TBase<TC,1>(bval){ pvar[0]=bval; };
TC show_A(void){return pvar[0];};
};

int main (void)
{
TClass<int> tc(10);
cout << tc.show_B() << tc.show_A() << endl;
return 0;
}

---------------------------------------------------------------------------------------


error (here in g++):
-----------------------------------------------------------------------------------------
g++ -W -Wall -o runtest maintest.cc
maintest.cc: In constructor 'TClass<TC>::TClass(TC)':
maintest.cc:20: error: 'pvar' was not declared in this scope
maintest.cc: In member function 'TC TClass<TC>::show_A()':
maintest.cc:21: error: 'pvar' was not declared in this scope

  Réponse avec citation
 
Page generated in 0,04886 seconds with 9 queries