[SOLVED] g++ error message no matching function for call to some function
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
g++ error message no matching function for call to some function
Hi all,
I got a confusing error message when compiling the C++ code:
Code:
]$ g++ -c testcls.cc -o testcls.o
testcls.cc: In member function `int testcls::open(const char*)':
testcls.cc:14: error: no matching function for call to `testcls::open(const char*&, int)'
testcls.cc:13: note: candidates are: int testcls::open(const char*)
If the member function is renamed to something else, the compiler won't complaint anymore. Why? and how to work around without modifying the function name? Please.
Code:
$ g++ --version
g++ (GCC) 3.4.6 20060404 (Red Hat 3.4.6-4)
Copyright (C) 2006 Free Software Foundation, Inc.
Last edited by Jerry Mcguire; 04-13-2010 at 04:53 AM.
I got a confusing error message when compiling the C++ code:
Code:
]$ g++ -c testcls.cc -o testcls.o
testcls.cc: In member function `int testcls::open(const char*)':
testcls.cc:14: error: no matching function for call to `testcls::open(const char*&, int)'
testcls.cc:13: note: candidates are: int testcls::open(const char*)
If the member function is renamed to something else, the compiler won't complaint anymore. Why? and how to work around without modifying the function name? Please.
Code:
$ g++ --version
g++ (GCC) 3.4.6 20060404 (Red Hat 3.4.6-4)
Copyright (C) 2006 Free Software Foundation, Inc.
nice link, but not very related in my case I guess.
The function prototypes are different in my example. Can't figure out why the compiler doesn't distinguish the two.
Code:
int testcls::open ( const char * ); // class testcls
int open ( __const char *, int , ... ); // fcntl.h
In C++ (unlike in "C") function names imply namespace prefix. No prefix, AFAIK, means current class prefix, that's why you get an error. You don't have in your class an 'open' function with the require signature.
If you used 'open' function from the link I provided you with with its namespace prefix, you wouldn't have had the error.
Last edited by Sergei Steshenko; 04-13-2010 at 08:42 PM.
IIUC, the fact that you used the .h version of the include for C library functions in C++ means it is in global namespace, so it is ::open
The source of the original confusion is that declaring a name in a class cannot overload the same name in global namespace. It masks that name in global namespace.
So you need to use ::open within the class to refer to the global open(). The difference in calling parameters does not prevent the member declaration from masking the global one.
I am doing code porting and trying to keep close to the original. There are obvious reasons not to change using other function or the result may not be desired. Yet, will do consider using fstream in future C++ developments.
Thank you again.
btw, the compiler does know where to find the global open() if my class member function is named differently, which is the trap. Perhaps the compiler may introduce a switch to make the difference.
Last edited by Jerry Mcguire; 04-13-2010 at 08:47 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.