0

I am having problems returning a struct.

I created a function currentPeriodCharges that would perform some calculations and return results for their use in another function.

one of the errors include: cannot overload functions distinguished by return type alone

any thoughts?

here is the struct:

typedef struct{
float cpCharges[3];
int cUsage[2];
}mystruct;

here is the function:

mystruct currentPeriodCharges (char a,int b,float c){
mystruct retVal;
int c=100;

if(a=='C'||a=='c'){
    retVal.cpCharges[2]=b*rate[1];
    retVal.cUsage[0]=0;
    retVal.cUsage[1]=0;
    retVal.cpCharges[0]=0;
    retVal.cpCharges[1]=0;
    return retVal;
}
    else{
        if(a=='R'||a=='r'){
            if(b<100){
                retVal.cpCharges[2]=b*rate[0];
                retVal.cUsage[0]=0;
                retVal.cUsage[1]=0;
                retVal.cpCharges[0]=0;
                retVal.cpCharges[1]=0;
                return retVal;
            }
                else{
                    if(b>100){
                        retVal.cUsage[0]=c;
                        retVal.cUsage[1]=b-retVal.cUsage[0];
                        retVal.cpCharges[0]=retVal.cUsage[0]*rate[0];
                        retVal.cpCharges[1]=retVal.cUsage[1]*rate[1];
                        return retVal;
                    }
                }
        }
    }
};
11
  • do you have more than one function with same name and list of arguments ? Commented Nov 26, 2013 at 5:17
  • no, the function currentPeriodCharges is the only function with that name and list of arguments. Commented Nov 26, 2013 at 5:21
  • does your compiler indicate where this error has occurred ? Commented Nov 26, 2013 at 5:21
  • Yes, a red squiggly line is placed under the function currentPeriodCharges. it also mention errors that have to do with the arrays in the function as well; Commented Nov 26, 2013 at 5:26
  • 'mystruct' : redefinition; symbol cannot be overloaded with a typedef, .cpCharges' must have class/struct/union type is ''unknown-type'' Commented Nov 26, 2013 at 5:27

2 Answers 2

1

Second error:

'mystruct' : redefinition; symbol cannot be overloaded with a typedef

is more meaningful here. The real problem must be right before the line mystruct currentPeriodCharges (char a,int b,float c).

In most cases is just missing semicolon, but it can be any error before that line.

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

Comments

0

(I don't have enough reputation yet to comment, so this is an "answer")

I think we need to see more of this code.

I'm also curious as to why we don't see a reported error of

Error   1   error C2082: redefinition of formal parameter 'c'

where the parm float c is in the function header and the int c=100; is in the body of text

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.