简体   繁体   English

Windows Linux c ++编译问题:“调用没有匹配功能”

[英]Windows Linux c++ compiling issue: “no matching function for call”

I am working on a tool that provides a facility to write small c++ code within the framework it provides. 我正在使用一种工具,该工具提供了在其提供的框架内编写小型c ++代码的工具。 The tool is windows and linux based. 该工具基于Windows和Linux。 We write code into the windows. 我们将代码写入Windows。 The compilation is done first on windows for testing purposes. 出于测试目的,首先在Windows上完成编译。 Finally a linux build is performed to actually run the whole production tests on linux. 最后,将执行一个Linux构建,以在Linux上实际运行整个生产测试。

I created a function with following signature: 我创建了一个具有以下签名的函数:

string myClass::myFunc(string& start, bool myflag, Class C1 & c1,
    long a=0, const char* b=NULL, void * c=NULL);

Now when the tool runs on windows (Microsoft visual express) everything works fine and all tests pass. 现在,当该工具在Windows(Microsoft Visual Express)上运行时,一切正常,所有测试均通过。

However when the code is compiled on linux I get an error stating that "no matching function for call". 但是,当代码在linux上编译时,出现错误,指出“没有匹配的调用函数”。

Here is the function signature: 这是函数签名:

string myClass::myFunc(string& start, bool myflag, Class C1 & c1,
    long a=0, const char* b=NULL, void * c=NULL);

Error message: 错误信息:

myfile.cpp: no matching function for call to 
myClass::myFunc(std::string, bool, classC1&, long int&, 
const char *&, void*&) 

myfile.h: note: candidates are: 
std::string myClass:myFunc(std::string&, bool&, classC1&, 
long int, const char*, void*)

I do not have any access to the linux server. 我无权访问linux服务器。 Hence cannot mention the linux distro or any other details. 因此,不能提及linux发行版或任何其他详细信息。

Thanks in advance. 提前致谢。

  • ftp FTP

Microsoft's C++ compiler incorrectly allows binding non- const references to temporary variables. 微软的C ++编译器错误地允许非绑定const临时变量的引用。 They won't fix the bug now, because it would break existing code. 他们现在不会修复该错误,因为它将破坏现有代码。 But that code already is broken on conformant compilers, as you've discovered. 但是,正如您所发现的那样,该代码已在兼容的编译器上损坏。

See if you can't pass by value (for small types) or by const reference (for ones that are expensive to copy). 查看您是否无法按值(对于小型类型)或const引用(对于复制成本高的值)进行传递。 If it's an output argument, you'll need to change the caller to pass an lvalue instead of a temporary. 如果它是输出参数,则需要更改调用方以传递左值而不是临时值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM