tenes razon, gracias, pero en realidad lo que quiero es que realmente
haya herencia, no solo que compile!

mira ahora agregando get()


template <typename T>
class Base
{
    T _t;

public:
    Base(T t) : _t(t) {}
};

template<typename T>
class Derived: public Base<T>
{
public:
    Derived(T t) : Base<T>(t) {}
    T get() { return _t; }
};

int main()
{
    Derived<int> d(1);
    int t = d.get();
    return 0;
}

template5.cpp: In member function 'T Derived<T>::get()':
template5.cpp:15: error: '_t' was not declared in this scope
make: *** [template5] Error 1

y si cambio
    T get() { return _t; }
por
    T get() { return Base<T>::_t; }

template5.cpp: In member function 'T Derived<T>::get() [with T = int]':
template5.cpp:21:   instantiated from here
template5.cpp:4: error: 'int Base<int>::_t' is private
template5.cpp:15: error: within this context
template5.cpp:4: error: 'int Base<int>::_t' is private
template5.cpp:15: error: within this context
make: *** [template5] Error 1

gracias.
_______________________________________________
Lista de correo Programacion.
[email protected]
http://listas.fi.uba.ar/mailman/listinfo/programacion

Responder a