L
liam_herron
Here is my code:
#include <iostream>
template<typename T>
class RawPtr
{
protected:
T* pointee_;
public:
RawPtr() : pointee_(0) {}
RawPtr(T* pT) : pointee_(pT) {}
};
template<typename T>
class SmartPtr : public RawPtr<T>
{
public:
SmartPtr() : RawPtr<T>() {}
explicit SmartPtr(T* pT) : RawPtr<T>(pT)
{
if (pointee_ != 0)
{
std::cout << "SmartPtr(T* pT): pointee_ non-null." <<
std::endl;
}
}
};
int main()
{
double *pDoubleRaw = new double(1.0);
SmartPtr<double> pDouble(pDoubleRaw);
return 0;
}
On Linux (g++ (GCC) 3.4.6 20060404 (Red Hat 3.4.6-3)) I get the
following compilation error:
g++ testInheritanceWithTemplates.cpp
testInheritanceWithTemplates.cpp: In constructor
`SmartPtr<T>::SmartPtr(T*)':
testInheritanceWithTemplates.cpp:27: error: `pointee_' was not
declared in this scope
On Windows, this compiles fine.
Any ideas why this doesn't work on Linux? Does the C++ standard think
that this is legal?
Regards,
Liam Herron
#include <iostream>
template<typename T>
class RawPtr
{
protected:
T* pointee_;
public:
RawPtr() : pointee_(0) {}
RawPtr(T* pT) : pointee_(pT) {}
};
template<typename T>
class SmartPtr : public RawPtr<T>
{
public:
SmartPtr() : RawPtr<T>() {}
explicit SmartPtr(T* pT) : RawPtr<T>(pT)
{
if (pointee_ != 0)
{
std::cout << "SmartPtr(T* pT): pointee_ non-null." <<
std::endl;
}
}
};
int main()
{
double *pDoubleRaw = new double(1.0);
SmartPtr<double> pDouble(pDoubleRaw);
return 0;
}
On Linux (g++ (GCC) 3.4.6 20060404 (Red Hat 3.4.6-3)) I get the
following compilation error:
g++ testInheritanceWithTemplates.cpp
testInheritanceWithTemplates.cpp: In constructor
`SmartPtr<T>::SmartPtr(T*)':
testInheritanceWithTemplates.cpp:27: error: `pointee_' was not
declared in this scope
On Windows, this compiles fine.
Any ideas why this doesn't work on Linux? Does the C++ standard think
that this is legal?
Regards,
Liam Herron