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

i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
Will Gunn
  • 305
  • 3
  • 5
  • 14

4 Answers4

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)
Nawaz
  • 353,942
  • 115
  • 666
  • 851
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.

K-ballo
  • 80,396
  • 20
  • 159
  • 169
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?

Adam Maras
  • 26,269
  • 6
  • 65
  • 91
1

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

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186