This is a problem that arose while using GNU G++ 3.4.5 under Linux.
The problem is: 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.
Below is the example I used and some of the things I tried and the gnu
errors I got. There are only two classes, Base and Derived, where
Base defines the buffer, and Derived tries to set a pointer to it.
Is this a gnu g++ issue or is there some syntax I missing?
Rick
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<chardah;
}