stdcxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: Errors compiling examples - Sun studio 11
Date Tue, 14 Feb 2006 20:50:53 GMT
Dipak Bapatla wrote:
> I have changed the code as follows in the two definitions in _tree.h to
> get the examples to compile.
>       const_iterator _C_make_iter (const _C_link_t __node) const {
>         return const_iterator (*this, _C_tree_citer (__node));
>     }
> 
>       to 
>    
>       const_iterator _C_make_iter (_C_link_t __node) const {
>         return const_iterator (*this, _C_tree_citer (__node));
>     }
> 
>  Removed the const from the parameter type. 

Okay, I think we're getting somewhere. I missed this in the error
message since it expands typedefs but the const is pointless there
since it doesn't do what I suspect the author thought it did (i.e.,
apply to the object type rather than to the pointer).

>    
>   It is weird that the compiler complained about the code because I have
> the test program below and it works fine as expected.

The bug is probably more subtle than that. Your program doesn't
involve templates. Does the more complicated test case below
compile?

Martin

template <class T> struct A { typedef T* P; };

template <class T>
struct B {
     typedef typename A<T>::P P;

     void foo (P) { }
     void foo (const P) const { }

     void bar () { foo ((P)0); }
     void bar () const { foo ((P)0); }
};

template <class T>
struct C {
     B<T> b;

     void bar () { b.bar (); }
     void bar () const { b.bar (); }
};

int main () {
     C<int> c;
     c.bar ();

     const C<int> d = C<int>();
     d.bar ();
}

Mime
View raw message