Witam serdecznie.
Mam problem dotyczący kilku klas (oczywiście kod przykładowy).
Może najpierw kod.
Szablony klas:
template <typename a1> class Connect
{
public:
a1 integer;
Connect() : integer(0) {};
Connect(a1 value);
a1 get_integer();
bool set_integer(a1 value);
};
template <typename classtype> class Inher_Connect :protected Connect<classtype>
{
public:
Inher_Connect();
Inher_Connect(classtype value);
classtype get_integer();
bool set_integer(classtype value);
};
Kilka metod tych klas:
template <typename classtype> Inher_Connect<classtype>::Inher_Connect() : Connect<classtype>() {};
template <typename classtype> Inher_Connect<classtype>::Inher_Connect(classtype value) : Connect<classtype>(value) {};
template <typename classtype> classtype Inher_Connect<classtype>::get_integer()
{return this->integer;};
template <typename classtype> bool Inher_Connect<classtype>::set_integer(classtype value)
{
try
{this->integer = value;}
catch (...)
{return false;}
return true;
}
template <typename a1> Connect<a1>::Connect(a1 value) : integer(value) {};
template <typename a1> a1 Connect<a1>::get_integer()
{return this->integer;};
template <typename a1> bool Connect<a1>::set_integer(a1 value)
{
try{this->integer = value;}
catch (...)
{return false;}
return true;
}
Problem dotyczy tego, że kompilacja przebiega prawidłowo tylko wtedy jeżeli definicje metod są umieszczone w pliku nagłówkowym klasy.
Jest to cholernie niewygodne.
Z początku myślałem, ze to ja robię coś źle, no ale okazało się, że to nie moja wina.
Zanim postanowiłem napisać posta na forum to rozejrzałem się trochę po internecie i znalazłem kilka rzeczy, które potencjalnie by rozwiązywały są sprawę, np.:
http://www.gamedev.pl/forum/definicja-metody-klasy-szablonowejhttp://xion.org.pl/files/texts/mgt/html/2_4.htmla nawet coś bardziej ekstremalnego
https://www.youtube.com/watch?v=RwdQA0pGWa4 (tego nie próbowałem)
Problem jest w tym, ze 2 pierwsze sposoby nie chcą działać, nwm dlaczego.
Jeżeli ktoś ogarnięty w temacie może mi pomóc wywalić te metody do pliku cpp to będzie mi bardzo miło.
Pozdrawiam i czekam na odpowiedź,
Robert