C++ me g++

Konstantinos Pistiolis kpistiolis at yahoo.com
Thu May 3 18:05:02 EEST 2001


--- The Reverant <reverant at freemail.gr> wrote:
> Paides xaireto. Paratheto ena mikro programmataki se
> C++ kai apo kato to 
> problima mou:
> 
> --cut here---------
> #include <iostream>
>  
> class AClass
> {
> public:
> int aFunc();
> };
>  
> int AClass::aFunc(){}
>  
> void main()
> {
> AClass myClass;
> int (*pFunc)()=myClass.aFunc;
> } 
> --cut here---------
> 
> To problima einai oti otan pao na to kano compile,
> pairno to eksis minima 
> lathous apo ton g++:
> 
> reverant at MagnusII:~ > g++ test.cpp
> test.cpp: In function `int main(...)':
> test.cpp:17: no matches converting function `aFunc'
> to type `int (*)()'
> test.cpp:10: candidates are: int AClass::aFunc()
> 
> Afto pou thelo na kano, einai na exo enan pointer se
> function, pou na deixnei 
> se mia member function tou object myClass (classis
> AClass). An thimamai kala, 
> se VC++ afto ginotan, o g++ petaei error. Ti den
> kano sosta?

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 ->*

> 
> Efxaristo prokatabolika
> 
> -- 
> The Reverant
> (Dimitris Stasinopoulos)
> 
> --
> linux-greek-users mailing list --
http://lists.hellug.gr

Mia asxeth symboylh: Opws soy eipa, oi synarthseis twn
klassevn kata t' alla einai kanonikes, ara oi static
metablhtes mesa se mia tetoia synarthsh EINAI KOINES
GIA OLA TA ANTIKEIMENA THS KLASSHS. Ayto prosexe to.

Filika Kwstas


__________________________________________________
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