5

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

JRL
  • 76,767
  • 18
  • 98
  • 146
plaisthos
  • 6,255
  • 6
  • 35
  • 63

4 Answers4

9

To call a function in the global namespace, use:

::solve(lp);

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

interjay
  • 107,303
  • 21
  • 270
  • 254
2

The C functions are in the global namespace. So try

::solve(lp)
mmmmmm
  • 32,227
  • 27
  • 88
  • 117
1

Please try ::solve

Drakosha
  • 11,925
  • 4
  • 39
  • 52
1

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

JRL
  • 76,767
  • 18
  • 98
  • 146