4

I have written the following class

class worker
{
   int action;
   int doJob(int type,int time = 0);
   public:
   int call();
}

And the function doJob is like

int worker::doJob(int type,int time = 0)
{
          ....code here
}

When i compile ,i am getting the following error

 error: the default argument for parameter 1 of 'int worker::doJob(int, int)' has not yet been parsed

Surely it is a problem with default parameter specification..So what is the problem with th e prototype?

3 Answers 3

5

You don't need to redefine the default value

int worker::doJob(int type,int time = 0)

can just be

int worker::doJob(int type,int time)

As you do not need to define the argument more than once.

Sign up to request clarification or add additional context in comments.

1 Comment

I take issue with "you don't need" and "can just be" above. You can't redefine the default value, and the first line must be changed to second line.
4

Put the default in the declaration (ie inside class worker in your example), but not in the definition, e.g. code simply:

 int worker::doJob(int type,int time)
 {  /* your code here */ }

Comments

1

int worker::doJob(int type,int time = 0) is giving you an error, you should only declare your default argument once.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.