primary-expression error?

I was practicing my object orianted programming when I had this error:

expected primary-expression before "void"
expected `;' before "void"

Any help would be appreciated. Here is the source code:

#include <iostream>
using namespace std;

class pet
int pet_ID;
int number;
cout <<"Now in the constructor\n" << endl;
void petID(void)
if(int number = 0; number < 5; number++;)
pet_ID = number;

int get_petID(void);

int pet::get_petID(void)
return pet_ID;

int main()
pet dog;
cout <<"Accessing dog's data" << endl;
cout <<"------------------------------\n" << endl;
cout <<"The dog's ID is: " << dog.get_petID();
cout <<"\n" << endl;

return 0;
In C++, you cannot define a function inside another function. You are trying to define the function void petID(void) inside the function pet().
Topic archived. No new replies allowed.