Posted By: Pat (Nesmrdi rum a smrdi prace) on 'CZprogram'
Title: C++
Date: Thu Jan 2 15:59:30 2003
Brej novej rock,
c++, prikladam programek a dotaz
<dotaz>
proc funguje:
t1::t1(string txt):text(txt){
cout << "Konstruktor t1 s parametrem " << text << endl;
}
a nefunguje
t2::t2(string txt):text(txt){
cout << "Konstruktor t2 s parametrem " << text << endl;
}
Udelal sem to jak uvedeno dole. Ale pokud je t2 potomek t1, mel by mit vsechny
atributy t1, ne? Takze i 'string text'. Resp. t2 to ma ale nemuzu k tomu
pristoupit pomoci toho prvniho pristupu, jako je u t1.
</dotaz>
<priklad>
#include <iostream>
#include <string>
#include <string>
using namespace std;
struct t1{
string text;
t1();
t1(string txt);
~t1();
};
struct t2: virtual t1{
t2(string txt);
t2();
~t2();
};
t1::t1(string txt):text(txt){
cout << "Konstruktor t1 s parametrem " << text << endl;
}
t1::t1(){cout << "Konstruktor t1" << endl;};
t1::~t1(){cout << "Destruktor t1" << endl;};
t2::t2(string txt){
text = txt;
cout << "Konstruktor t2 s paramatrem " << text <<endl;
}
t2::t2(){cout << "Konstruktor t2" << endl;};
t2::~t2(){cout << "Destruktor t2" << endl;};
int main(){
t1 var1("Test");
t2 var2("Trest");
return 0;
}
</priklad>
<podekovani />
Nehodlam vysvetlovat a ...
... Sipu si popel na *hlavu*