2

I have already searched for this type of error and found a few threads, but each one recommended using #ifndef to make sure the header file is only loaded once. I have done this and still get an error. The odd thing is this error: circle.cc:25:6: error: prototype for ‘void circle::populate_classobj(int, int, int)’ does not match any in class ‘circle’ says my function only has 3 int's but every place i have that function, i have 4 ints.

here is my class header file

#ifndef _CIRCLE_H_
#define _CIRCLE_H_
#define PI 3.14159


class circle
{
public:
    float radius(int x1, int x2, int y1, int y2);
    float circumference(float d);
    float area(float d);
    void populate_classobj(int, int, int, int);

protected:
    float distance(int x1, int x2, int y1, int y2);


private:
    int x1, y1, x2, y2;

};

#endif // _CIRCLE_H_

Here is my function call in my class file circle.cc

void circle::populate_classobj(int cx1, int cx2, int cy1, int cy1)
{
    x1=cx1;
    x2=cx2;
    y1=cy1;
    y2=cy2;
}

and here is what i actually call in main

mycircle.populate_classobj(x1,x2,y1,y2);

there are variables called x1, x2, y1, y2 in main

The really odd thing is that the redefinition error is only for cy1, not cx1, cx2 or cy2

Thanks for any help and if you need to see more of my code, ask for it.

-Will

5
  • 4
    cy1 is declared twice in the method definition, there is no cy2. Looks like copy and paste.
    – asm
    Oct 3, 2011 at 17:22
  • Thanks jeff, I had clicked the code button, but it only made my #define tags large and bold
    – Will Gunn
    Oct 3, 2011 at 17:23
  • facepalm Thanks Andrew, I can't believe I didn't see that.
    – Will Gunn
    Oct 3, 2011 at 17:24
  • BTW, you should not define your own PI... there is already M_PI in math.h/cmath with a bit more precision than the one you are using Oct 3, 2011 at 17:30

4 Answers 4

4

Last two parameters are exactly same as shown below. Hence the redefinition error.

void circle::populate_classobj(int cx1, int cx2, int cy1, int cy1)
                                                     ^^^      ^^^

I think you wanted to write:

void circle::populate_classobj(int cx1, int cx2, int cy1, int cy2)
3
void circle::populate_classobj(int cx1, int cx2, int cy1, int cy1)

You see there the redefinition of cy1, since both last arguments are called the same. By the way, names beginning with an underscore in the global namespace are reserved for the implementation, you should drop the leading underscore from your scope guards.

0
3
void circle::populate_classobj(int cx1, int cx2, int cy1, int cy1)
//                                                   ^^^      ^^^

Is this a question typo, or do you really have two parameters in the function definition named cy1?

1

Your definition of populate_classobj uses the same name cy1 for two different parameters.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.