C++ me g++
Konstantinos Pistiolis
kpistiolis at yahoo.com
Thu May 3 20:52:01 EEST 2001
--- The Reverant ?reverant at freemail.gr? wrote:
? When the time was Thursday 03 May 2001 17:29,
? Konstantinos Pistiolis wrote:
? ? Opa, ayto poy 8es den ginetai akribws etsi... Allo
? ? deikths se mia synarthsh poy den pairnei tipote
? kai
? ? epistrefei int, dhladh ?int (*)()? kai allo
? deikths se
? ? mia synarthsh antikeimenoy ?AClass? poy dinei int.
? ? dhladh ?int (AClass::*)()?
? ? En oligois, oi synarthseis poy einai melh
? klassewn,
? ? de diaferoyn KA8OLOY APO TIS ALLES gia ayto
? yparxei
? ? MONO MIA SYNARTHSH gia ola ta antikeimena. Ara
? otan
? ? kaleis mia tetoia synarthsh ayth den kserei se
? poio
? ? antikeimeno kaleitai kai prepei epipleon na dwseis
? kai
? ? to deikth sto antikeimeno ektos toy deikth sth
? ? synarthsh.....
? ? 8a eprepe dhladh na peis
? ? int (AClass::*pFunc)()=myClass.aFunc;
? ? anti gia
? ? int (*pFunc)()=myClass.aFunc;
? ? poy orizei ton pFunc sa deikth se tetoia
? synarthsh
? ? poy einai mellos se tetoioy typoy antikeimeno...
? ?
? ? mono etsi o deikths pFunc einai pliris, alla
? prepei
? ? parallhla NA DINEIS KAI TO ANTIKEIMENO, dhladh edw
? h
? ? klhsh 8a ginei me ena deikth kai ena antikeimeno:
? ? (myClass.*pFunc)();
? ? me th boh8eia toy telesth .*
? ? Antistoixa yparxei kai o telesths -?*
?
? To problima einai kapos pio sintheto...to
? programmataki pou edosa pio pano
? einai ena cut down enos programmatos peripou 2k
? grammon, kai den skeftika oti
? tha iparxoun kai alles sinepeies. Etsi to basiko
? problima einai oti o diktis
? pFunc prepei na perasei os parametros stin gnosti
? mas signal, etsi oste otan
? px. to programma lambanei SIGINT, na ekteleitai i
? void AClass::pFunc(int
? anInt), tou antikeimenou myClass. Note oti to
? myClass einai to monadiko
? instance tis AClass pou tha dimiourgeitai mesa sto
? programma. Poia einai
? loipon i sosti sintaksi tis entolis signal()?
? Prospathisa polla alla panta
? ktipaei o g++...
?
Tote allazei to pramma, den 8es deikth se synarthsh
klassews all se koinh synarthsh kai malista synarthsh
C kai oxi C++.
Kanonika 8a eprepe na ftiakseis mia synartish ektos
klasews kai me dhlwsh:
extern "C" int myFunc();
h opoia fysika den mporei na einai se klassh.
Edw yparxei ena kolpo. Mporeis na kaleseis mia
synarthsh klassews XWRIS NA EXEIS KANENA ANTIKEIMENO,
arkei h synarthsh ths klassews na einai 'static'
an eixes dhladh
class AClass{
static int myFunc();
};
tote OLA OSA H8ELES NA KANEIS APO TIN ARXH GINONTAI
(xwris dhladh .*). To mega problima einai omws oti oi
static synarthseis den mporoyn na 'doyn' mh static
melh ths klassews, opote h kaneis olh thn klash static
h ftiaxneis mia asxeth synarthsh gia th signal() poy
8a kalei th mh statikh myFunc() panw sto monadiko
antikeimeno soy (proteino).
Mporeis epishs na baleis ton 'this' pointer ws statikh
metablhth sthn klassh soy, kai h statikh myFunc() 8a
kalei ta alla melh ws thisPrt->...
Genika se endiaferei h synarthsh poy 8a paei sti
signal() (ths klasews h oxi) na exei ena deikth pros
to monadiko antikeimeno AClass.
Prosoxh: oi synarthseis typoy C diaferoyn apo tis C++.
sth "C" h myFunc() PAIRNEI APEIRA ORISMATA
enw sth "C++" h myFunc() den pairnei tipote
sth C++ 8a eprepe na peis static int
AClass::myFunc(...) gia na tairiazei me ti C
Akoma, den kserw an einai swsto na dineis sth
signal() deikth se C++ synarthsh, an kai panta moy
doylepse...
Elpizw na se boh8hsa,
koita pantws 'man signal' giati nomizw oti allazei o
typos ths signal() gia C, kai C++ programma. Den exw
linux edw gia na to dw (sto IRIX pantws etsi einai)
Kalh tyxh
? Efxaristo kai pali kai esena Konstantine alla kai
? ton filo Efstathiou.
?
? --
? The Reverant
? (Dimitris Stasinopoulos)
?
? ?Eimaste Mafiozoi.
? Mas xtipate, sas xtipame.
? Einai i douleia mas.?
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/
More information about the Linux-greek-users
mailing list