Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;:使用常量字符串引用作为构造函数参数_C++_Eclipse_String - Fatal编程技术网

C++ C++;:使用常量字符串引用作为构造函数参数

C++ C++;:使用常量字符串引用作为构造函数参数,c++,eclipse,string,C++,Eclipse,String,在eclipse中,它不会给我任何问题,当我尝试用g++从终端编译时,它会说 MyClass.cpp:(.text+0x129):对“MyClass2::MyClass2(int,std::basic_string,std::allocator>,int,int,double)”的未定义引用 对于一行,我只需为构造函数参数传递一个带引号的字符串行“thisValue”。如果将参数的类型更改为正则字符串,这很好,但是当我执行conststring&相反,g++会抱怨,eclipse不会。为什么会这

在eclipse中,它不会给我任何问题,当我尝试用g++从终端编译时,它会说

MyClass.cpp:(.text+0x129):对“MyClass2::MyClass2(int,std::basic_string,std::allocator>,int,int,double)”的未定义引用


对于一行,我只需为构造函数参数传递一个带引号的字符串行“thisValue”。如果将参数的类型更改为正则字符串,这很好,但是当我执行conststring&相反,g++会抱怨,eclipse不会。为什么会这样?

您必须显示一些代码。我怀疑你的声明和实现不同。不,他们没有。否则,当我在终端中运行make时,eclipse如何解释它,而不是g++呢?“未定义引用”表示链接器错误。如果它在Eclipse中工作,那么问题可能出在构建命令/Makefile中。发布用于构建项目的命令。但是,当arg被定义为string而不是const string时,为什么它可以工作?它可能不知道如何将const char*隐式转换为const string&?