-5

I am making a new program in c++ i get the current error

expected primary-expression before ‘int’

about this line

p1::pascals_triangle(int depth);

My code is:

this is my 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.      

this is main

    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);
zero298
  • 25,467
  • 10
  • 75
  • 100
Technupe
  • 4,831
  • 14
  • 34
  • 37
  • 6
    Show us the code! – Keith Mar 03 '11 at 02:06
  • 2
    He didn't mean format the code! He meant show us some context! That one line uses a namespace or class and a function/method in it that take an integer as a parameter. Where are all of those things declared and defined? X| – Sion Sheevok Mar 03 '11 at 02:17

2 Answers2

1

Unless you're declaring a method, you probably don't need the keyword "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;
}

If I were to write instead:

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

I'd get:

In function ‘int main()’:
error: expected primary-expression before ‘int’
Dan
  • 141
  • 1
  • 3
  • `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. ` – Technupe Mar 03 '11 at 02:13
  • @user570098: whoa. Offering bits and pieces? So where does `p1` come from? We know now it's a namespace at least ... – 0xC0000022L Mar 03 '11 at 02:16
0

p1 needs to be an existing namespace or class name.

If that does not solve the problem you will have to give some surrounding code to make sense of your question ;)

Good luck.

0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
  • 'code' int main(int argc, char *argv[]) { double (*pf)(double k); // declares the function pointer pf = &p1::test_function;//test_function; // sets the value of 'pf' to the add\ ress of the 'p1::test_function' function. p1::pascals_triangle(int depth); return 0; } 'code' – Technupe Mar 03 '11 at 02:09
  • 2
    @user570098: Edit the code into the question, and be sure to indent it four places so it will be formatted as code. As-is, it's impossible to be certain where your single-line comments end. – Jerry Coffin Mar 03 '11 at 02:12
  • @user570098: that does not answer the question about `p1` ;) – 0xC0000022L Mar 03 '11 at 02:14