Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > please help me in distinguish redefining functions, overloading functions and overriding functions.

Reply
Thread Tools

please help me in distinguish redefining functions, overloading functions and overriding functions.

 
 
Xiangliang Meng
Guest
Posts: n/a
 
      06-21-2004
Hi, all.

When reading C++ books, I'm alway confused by those terms "redefining
functions", "overloading functions" and "overriding functions".

Please give me some comments on those terms. Thanks.

If giving more strategy hehind them, more helpful.

Best Regards,

Xiangliang Meng


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      06-21-2004
"Xiangliang Meng" <(E-Mail Removed)> wrote...
> When reading C++ books, I'm alway confused by those terms "redefining
> functions", "overloading functions" and "overriding functions".
>
> Please give me some comments on those terms. Thanks.
>
> If giving more strategy hehind them, more helpful.


Overloading is defining functions with the same name but with
different arguments in the _same_scope_. For example, members
of the same class would be overloaded if they have the same
name but different arguments (even just 'const' after the
function declaration counts):

struct foo {
void overloaded();
void overloaded(int); // same scope
};

Redefining (correct term is "hiding") is declaring a function
(and in fact, any symbol) with the same name in a more enclosed
scope. For the consistency's sake, derived classes' scope is
considered more enclosed than the base class' one.

struct base {
void somefunction();
};

struct derived : base {
void somefunction(int); // hides base::somefunction
};

Overriding relates to _virtual_ function _only_. And it can
happen if the function that overrides has the _same_ arguments:

struct base {
virtual void foo();
};

struct derived : base {
void foo(); // overrides base::foo
};

struct derived2 : base {
void foo(int); // does NOT override but instead _hides_
};

As to strategy, I am not sure what to tell you. Each of those
language features has its uses. Practice.

Victor


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
overloading non-template member functions with template member functions Hicham Mouline C++ 0 04-23-2009 11:42 AM
redefining functions andreyvul C Programming 16 12-01-2008 09:09 AM
difference betweeen overloading and overriding yashwant pinge C++ 8 04-17-2007 07:18 AM
still confused about headers, inline functions, linking, and redefining pookiebearbottom@yahoo.com C++ 6 07-18-2006 05:55 PM
Diff btwn Function overloading and overriding iceColdFire C++ 11 05-18-2005 06:12 AM



Advertisments