C++:外部“C”与外部之间的命名空间冲突和班级成员

发布于 2024-08-30 11:57:35 字数 437 浏览 4 评论 0原文

我偶然发现了一个相当奇特的 c++ 命名空间问题:

简明示例:

 extern "C" {
 void solve(lprec * lp);
 }

 class A {
 public:
    lprec * lp;
    void solve(int foo);
 }

 void A::solve(int foo)
 {
     solve(lp);
 }

我想在我的 C++ 成员函数 A::solve 中调用 c 函数solve。编译器对我的意图不满意:

  error C2664: 'lp_solve_ilp::solve' : cannot convert parameter 1 from 'lprec *' to 'int'

我可以在求解函数前添加一些前缀吗? C::解决不起作用

I stumbled upon a rather exotic c++ namespace problem:

condensed example:

 extern "C" {
 void solve(lprec * lp);
 }

 class A {
 public:
    lprec * lp;
    void solve(int foo);
 }

 void A::solve(int foo)
 {
     solve(lp);
 }

I want to call the c function solve in my C++ member function A::solve. The compiler is not happy with my intent:

  error C2664: 'lp_solve_ilp::solve' : cannot convert parameter 1 from 'lprec *' to 'int'

Is there something I can prefix the solve function with? C::solve does not work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

呆° 2024-09-06 11:57:35

要调用全局命名空间中的函数,请使用:

::solve(lp);

无论该函数是否为 extern "C" ,都需要这样做。

To call a function in the global namespace, use:

::solve(lp);

This is needed whether the function is extern "C" or not.

甜妞爱困 2024-09-06 11:57:35

C 函数位于全局命名空间中。所以尝试一下

::solve(lp)

The C functions are in the global namespace. So try

::solve(lp)
維他命╮ 2024-09-06 11:57:35

请尝试 ::solve

Please try ::solve

相权↑美人 2024-09-06 11:57:35

只需::solve(lp)。请注意,您的类声明后还需要一个分号。

Simply ::solve(lp). Note you also need a semicolon after your class declaration.

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