C++. Error while passing pointer by reference.
Kirill Berezin
kyb22@rol.ru
Fri Dec 5 09:37:00 GMT 2008
Hie.
I crossed the very curious sample of code the gcc failed to compile.
Here is the example:
#include <stdio.h>
#include <stdlib.h>
class test {
public:
int func(int*& a1){
a2 = a1;
return 0;
}
void print(){ printf("0x%X \n", a2);};
private:
int* a2;
};
int main(){
int* a;
int c;
test b;
//
b.func(&c);
b.print();
return 0;
}
ц⌠++ prints the following error
test05.cc: In function 'int main()':
test05.cc:27: error: no matching function for call to 'test::func(int*)'
test05.cc:12: note: candidates are: int test::func(int*&)
I think that it is reasonable not to compile, because, for example, it
would not possible to guess a correct function to overload. But The C++
standard, at first glance, does not prohibit such a coding style.
May be I was wrong in my suggestions, and this is a very useful and
progressive style.
It would be nice to hear any opinions.
Kirill.
--
ц╚ц┴ц▓ц┴ц▄ц▄ ц╒ц┘ц▓ц┘ц ц┴ц▌ <kyb22@rol.ru>
цЁц■ц│ц▓ц⌡ц┴ц┼ ц┴ц▌ц√ц┘ц▌ц┘ц▓-ц░ц▓ц▐ц┤ц▓ц│ц█ц█ц┴ц⌠ц■
ц╖ц▓ц∙ц░ц░ц│ ц▓ц│ц ц≈ц┴ц■ц┴ц▒ ISP ц⌠ц┴ц⌠ц■ц┘ц█, цЁц▐ц≈ц┴ц▌ц■ц┘ц▄
ц╖ц▓ц∙ц░ц░ц│ ц╚ц▐ц█ц░ц│ц▌ц┴ц┼ ц╥ц≥ц█ц░ц┘ц▄ц╚ц▐ц█
More information about the Gcc-help
mailing list