将 const char* 传递给方法,但得到 char const * 错误

发布于 2024-11-28 10:51:37 字数 757 浏览 1 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坏尐絯℡ 2024-12-05 10:51:37

char const *const char * 完全相同。您的问题与消息的那部分无关。您的错误是您正在调用函数 benchmark::GetBiPoly(),但链接器无法在您链接的对象中找到它。该函数在哪里定义的?你正在链接它吗?它在那个命名空间中吗?

char const * and const 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 function benchmark::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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文