Redeclaration a member function

Feb 7, 2010 at 12:35am
Hi there!

I'd like to know why I can't redeclare a member function ( http://msdn.microsoft.com/en-us/library/48c0x0f6%28VS.80%29.aspx ).

For example, this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class TTT
{
   void fun();
   void fun()    // <---- Redeclaration !!!
   { }
};

//----------------------

class AAA
{
   void fun();
};

void AAA::fun()
{ }
void AAA::fun(); // <---- Redeclaration !!! 


is incorrect...

But why is that ? In the case of normal functions, a redeclaration doesn't matter...
Feb 7, 2010 at 12:44am
I can't come up with an answer, but, why would you ever need to do that?
Feb 7, 2010 at 12:46am
Because it doesn't make any sense.

Redeclaring would unnecessary duplicate code. That's bad for several reasons. (Maintainability reasons, mostly)

I suspect the only reason it's allowed for global functions is to retain compatibility with C, which is less strict about things like that.
Topic archived. No new replies allowed.