-5

C ++で新しいプログラムを作成していますが、現在のエラーが発生します

'int'の前に期待される一次式</p>

この行について

p1::pascals_triangle(int depth);

私のコードは次のとおりです。

これは私のfunctions.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);
4

2 に答える 2

1

メソッドを宣言しているのでない限り、キーワード「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;
}

私は得るだろう:

In function ‘int main()’:
error: expected primary-expression before ‘int’
于 2011-03-03T02:10:08.163 に答える
0

p1namespace既存の名前またはクラス名である必要があります。

それでも問題が解決しない場合は、質問を理解するために周囲のコードを指定する必要があります;)

幸運を。

于 2011-03-03T02:07:24.650 に答える