将 const char* 传递给方法,但得到 char const * 错误
我的 C++ 代码遇到了有线问题。我正在使用 TCLAP 软件接受命令行参数,其中一个标志是文件名:
TCLAP::ValueArg<string> Poly ("p", "poly", "file name of the polynomial", false, "", "string");
我还有另一个接受 3 个参数的函数,
void GetBiPoly(const char *filename, BiPoly<BigFloat> *u, BiPoly<BigFloat> *v);
我将 Poly 字符串传递给函数 GetBiPoly
这样:
benchmark::GetBiPoly(Poly.getValue().c_str(), &fxy, &gxy);
当我编译程序时,它给我以下错误:
miranda.cpp:(.text+0x1900): undefined reference to `benchmark::GetBiPoly(char const*, CORE::BiPoly<CORE::BigFloat>*, CORE::BiPoly<CORE::BigFloat>*)'
似乎唯一的区别是错误信息中文件名的类型是 char const* ,而定义是常量字符*。谁能告诉我这似乎是什么问题?谢谢。
I encountered a wired problem on my C++ code. I'm using TCLAP software to accept command line arguments, and one of the flags is a file name:
TCLAP::ValueArg<string> Poly ("p", "poly", "file name of the polynomial", false, "", "string");
I also have another function that accepts 3 parameters,
void GetBiPoly(const char *filename, BiPoly<BigFloat> *u, BiPoly<BigFloat> *v);
I'm passing the Poly string to the function GetBiPoly
in this way:
benchmark::GetBiPoly(Poly.getValue().c_str(), &fxy, &gxy);
When I compile the program, it gives me the following error:
miranda.cpp:(.text+0x1900): undefined reference to `benchmark::GetBiPoly(char const*, CORE::BiPoly<CORE::BigFloat>*, CORE::BiPoly<CORE::BigFloat>*)'
It seems like the only difference is that the type of the file name in the error information is char const*
, while the definition is const char*
. Can anybody tell me what the problem it seems to be? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
char const *
和const char *
完全相同。您的问题与消息的那部分无关。您的错误是您正在调用函数benchmark::GetBiPoly()
,但链接器无法在您链接的对象中找到它。该函数在哪里定义的?你正在链接它吗?它在那个命名空间中吗?char const *
andconst char *
are exactly the same thing. Your problem is not related to that part of the message. Your error is that you're calling the functionbenchmark::GetBiPoly()
, but the linker can't find it in the objects you're linking. Where is that function defined? Are you linking it? Is it in that namespace?