Hi all,

the following code fails with gcc 4.4.3,4.5.0 and 4.6 snapshot (some weeks old) 
:

<snip>

#include <iostream>

using namespace std;


class A
{
    public:
        static const int x=10;
};

class Zgr_A
{
    public:
        A* operator->() { return (A*)0; }
};

template <class T>
class  Zgr
{
    public:
        T* operator->() { return (T*)0; }
};

int main()
{
    A a_direct;
    A* a_ptr;
    Zgr_A a_indirect_ptr;
    Zgr<A> a_template_ptr;

    A* ptr_from_indirect= a_indirect_ptr.operator->();

    cout << "0. " << A::x << endl;
    cout << "1. " << a_direct.x << endl;
    cout << "2. " << a_ptr->x << endl;
    cout << "3. " << a_indirect_ptr->x << endl;
    cout << "4. " << a_template_ptr->x << endl;
    cout << "5. " << ptr_from_indirect->x << endl;
    cout << "6. " << a_template_ptr.operator->()->x << endl;
    cout << "7. " << ((A*)(a_template_ptr.operator->()))->x << endl;

    return 0;
}

</snap>

Result:
g++ -g main.cpp -o go
/tmp/ccABoZtk.o: In function `main':
main.cpp:37: undefined reference to `A::x'
main.cpp:38: undefined reference to `A::x'
main.cpp:40: undefined reference to `A::x'
main.cpp:41: undefined reference to `A::x'
collect2: ld returned 1 exit status

Is my code wrong or is it a compiler bug? If the code is wrong, I expect a 
compiler error not a linker message!

Wondering... 
 Klaus

P.S. Borland C++ compiles and links correct.


-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de

Reply via email to