ошибка в выражении int основного файла c ++ - PullRequest
0 голосов
/ 03 марта 2011

Я делаю новую программу на C ++, я получаю текущую ошибку

ожидаемое первичное выражение перед 'int'

об этой строке

p1::pascals_triangle(int depth);

Мой код:

это мои функции.cpp

using namespace std;

/**                                                                             
 * Note the namespace qualifier used here - I did not bring 'p1' in             
 * scope, therefore we need the "p1::" to preceed the function definitions.     
 */
void p1::pascals_triangle(int depth) {
  // Implement problem 1 in here.      

это главная

    using namespace std;

int main(int argc, char *argv[]) {

  // Need to implement argument processing here                                                                        
  // If you want to set a function pointer, you just take the                                                          
  // address of the function ('&' means 'take address of'):                                                            

  double (*pf)(double k); // declares the function pointer                                                             
  pf = &p1::test_function;//test_function; // sets the value of 'pf' to the address of      the 'p1::test_function' functio\
   n.                                                                                                                     

  p1::pascals_triangle(int depth);

Ответы [ 2 ]

1 голос
/ 03 марта 2011

Если вы не объявляете метод, вам, вероятно, не нужно ключевое слово "int".

#include <iostream>


namespace foo {
    void pascals_triangle(int depth) {
        std::cout << depth << std::endl;
    }

    int another_method(int y);
}

using namespace std;

int
foo::another_method(int y) {
    cout << "called another_method with " << y << endl;
    return 8;
}

int main(void) {
    int x = 5;
    foo::pascals_triangle(x);
    foo::another_method(x + 1);
    return 0;
}

Если бы я написал вместо этого:

int main(void) {
    int x = 5;
    foo::pascals_triangle(int x);
    foo::another_method(x + 1);
    return 0;
}

I 'получаю:

In function ‘int main()’:
error: expected primary-expression before ‘int’
0 голосов
/ 03 марта 2011

p1 должно быть существующим namespace или именем класса.

Если это не решит проблему, вам придется дать некоторый окружающий код, чтобы понять ваш вопрос;)

Удачи.

...