error: default argument for `int&ns1' has type `int'. i cant figure out why this error is popping up it says the error is on line 3, anyone know how to help?

#include<iostream>
using namespace std;
void score_num(int &ns1=0,int &ns2=2,int &ns3=3, int &ns4=4, int &ns5=5, int &n6=6, char gam_answ);
void display_score(int curr_score);
void roll_hold(int roll, int answer, int turn);
void turn_it_is();
void char play_again(char letter, char 'y', char 'n');
void int score_num(int& ns1, int& ns2, int&n s3, int& ns4, int& ns5, int& ns6, char gam_answ, turn)
{
    while(char ns1=0)
    {
        cout << " next player " << ((turn % 2) ==1);
        cout << " please select r for roll and h for hold ";
        cin >> gam_answ;
        gam_answ++;
    }

Recommended Answers

All 5 Replies

Default arguments should be at the right of the declaration.

eg.

int func( int x, int y = 1, int z = 2 );

you cannot have variables which do not have a default definition on the right hand side of those that do.

int func( int x = 1, int y = 2, int z );  // not allowed

the rules concerning the definition of default arguments are a litle unintuitive. the first is that the default values are resolved positionally begginning with the right most parameter, so if a paramter has a default value then all the paramteres on the right must also have default values. the second is that the default value can only be specified once, either in the declaration or the definition of the function, but not both.

beyond that, the code as posted will not even compile. the fucntion declaration does nto match the function definition.

void score_num(int &ns1=0,int &ns2=2,int &ns3=3, int &ns4=4, int &ns5=5, int &n6=6, char gam_answ);  // does not match

void int score_num(int& ns1, int& ns2, int&n s3, int& ns4, int& ns5, int& ns6, char gam_answ, turn)  // this
{

you even have an extra parameter here with no type specifed.

Please post working code.

beyond that, the code as posted will not even compile. the fucntion declaration does nto match the function definition.

void score_num(int &ns1=0,int &ns2=2,int &ns3=3, int &ns4=4, int &ns5=5, int &n6=6, char gam_answ);  // does not match

void int score_num(int& ns1, int& ns2, int&n s3, int& ns4, int& ns5, int& ns6, char gam_answ, turn)  // this
{

you even have an extra parameter here with no type specifed.

Please post working code.

i know thats what i need help on

Well, then I would suggest that a good starting point would be to fix the problem with the default arguments and then make the function definition match the function declaration, and then see where you are from there.

Look regarding the actual error message you posted check the function for usage of ns1.

void int score_num(int& ns1, int& ns2, int&n s3, int& ns4, int& ns5,

here you declare the parameter ns1 as a int reference and then you attempt to set it to a default integer value. The compiler cannot convert from and int to an int reference. A reference needs to be bound to an object, not a value.

That is just for starters though.

Try to get a basic function that compiles and then work from there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.