‘int Foo::bar()’ cannot be overloaded

From Cppsyntax

Jump to: navigation, search

You can get the error

 ‘int Foo::bar()’ cannot be overloaded

if you declare (.h file) and define (.cc file) Foo::bar() slightly differently. For example, if you declare bar() to be int* (a pointer) in the .h and define it to be int (not a pointer) in the .cc, you will get this complaint.

You can also get this error if your declaration and definition don't agree on whether the method is const or not.

WRONG

 Foo.h:
   class Foo
   {
     public:
       int* bar();     // pointer
   }
 Foo.cc:
 int bar()             // not a pointer
 {
   // stuff
 }

RIGHT

 Foo.h:
   class Foo
   {
     public:
       int* bar();     
   }
 Foo.cc:
 int* bar()            // yay, it matches        
 {
   // stuff
 }
Personal tools