wrote:
> 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.
If the member is in another dependant base class, then the compiler
can't deduce what buffer_ is and so you get an error. Using, this->,
while redundant in non templated classes, tells the compiler that
buffer_ is dependant on the template parameters.
>
> 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?
I think g++ is right.
>
> Rick
>
>
> template <typename CharT>
> class Base
> {
> public:
> CharT buffer_;
> };
>
>
> template <typename CharT>
> class Derived: public Base<CharT>
> {
> public:
> Derived( void)
> {
CharT * ptr = & this->buffer_;
> 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;
> }
>