This is a problem that arose while using GNU G++3.4.5. The problem is simple: How to get a pointer value from a templated object inside a class? Normally, I would add an '&' can carry on. This does not seem to work.
Take a look at the example and some of the things I tried. There are only two classes, Base and Derived, where Base defines the buffer, and Derived tries to set a pointer to it.
If you take away the template specification, everything works like it should.
Any ideas?
Rick
Take a look at the example and some of the things I tried. There are only two classes, Base and Derived, where Base defines the buffer, and Derived tries to set a pointer to it.
If you take away the template specification, everything works like it should.
Any ideas?
Rick
Code:
template <typename CharT>
class Base
{
public:
CharT buffer_;
};
template <typename CharT>
class Derived: public Base<CharT>
{
public:
Derived( void)
{
CharT * ptr = & buffer_; // error: `buffer_' was not declared in this scope
CharT * ptr = & Base<CharT>::buffer_; // error: cannot convert `char Base<char>::*' to `char*' in initialization
CharT * ptr = & (Base<CharT>::buffer_); // error: same as last one
// This works but sure is ugly
CharT & ref = Base<CharT>::buffer_;
CharT * ptr = & ref;
}
};
int main( void)
{
Derived<char> dah;
}
Comment