template class data member not found!

A

alex

Code:
=========================================
template <class T, int Len>
class COciVariable
{
public:
T m_Var[Len];
};

template <class T>
class COciVariableEx : public COciVariable<T, 1>
{
public:
void operator = ( const T & Var )
{
m_Var = Var;
}
};
===========================================
Platform:
===========================================
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk
--host=i386-redhat-linux
Thread model: posix
gcc version 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)
============================================
Error:
============================================
In file included from main.cpp:1:
test.h: In member function `void COciVariable2Ex<T>::eek:perator=(const
char&)':
test.h:35: error: `m_Var' undeclared (first use this function)
test.h:35: error: (Each undeclared identifier is reported only once for
each function it appears in.)


Why? PLS help me! Thx!!!
 
G

Greg

alex said:
Code:
=========================================
template <class T, int Len>
class COciVariable
{
public:
T m_Var[Len];
};

template <class T>
class COciVariableEx : public COciVariable<T, 1>
{
public:
void operator = ( const T & Var )
{
m_Var = Var;
}
};

Implement operator= like so:

void operator= ( const T & Var )
{
this->m_Var = Var;
}

Greg
 
D

dkotlyarov

Standard C++ says that nondependent names are not looked up in
dependent base classes. To correct the code you're to make m_Var
dependent. You can do it in two ways: this->m_Var or COciVariable<T,
1>::m_Var.
See "two-phase lookup" to get additional information.
 
J

Julien Hamaide

And as you m_Var is an array you should do this

public:
void operator = ( const T & Var )
{
this->m_Var[ 0 ] = Var;
}
};

alex a écrit :
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top