473,327 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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

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
Jul 22 '05 #1
1 2348
"Xiangliang Meng" <xi*************@hotmail.com> 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
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: AGoTH | last post by:
class A { public: virtual void foo(int b) {} virtual void foo(char* b) {} }; class B : public A{ virtual void foo(int b) {} };
7
by: bberu | last post by:
Hi, I know it is possible to refine operators (like +, -, * or /) on classes. But is it possible on simple types ? ex : If I have a type like : typedef int vector is it possible to redefine a...
11
by: iceColdFire | last post by:
Hi, What is the Diff btwn Function overloading and overriding thanks, a.a.cpp
8
by: Shea Martin | last post by:
I have a pure virtual f'n bool SaveData(). This f'n is called by SaveDataWithWarn(). The idea being the implementing class must define how data is saved, but the base class handles GUI operations,...
5
by: Laurent Allardin | last post by:
Hi, Why this code compile??? We should not be able to Override the code by using the Overloads since the sub as exactly the same parameters.... Thank you. Laurent Allardin,MCSD,MCAD
2
by: garyusenet | last post by:
I could do with something similiar, can you tell me if you think this would work for me, and if there's any advantage in working with controls this way than how I currently am. At the moment...
5
by: mohammaditraders | last post by:
Question # 1 Write a program which consists of a class named Student, the class should consists of three data members Name, Ob_marks, Total_marks and two member functions...
20
by: ramadeviirrigireddy | last post by:
Can anyone tell me whether the return type of the method will also be considered when you are overriding a method? what i mean exactly is whether the return type can be different when you are...
3
by: Rick | last post by:
One of the rules I have recommended for our new coding standard is as follows: "When overriding a base class virtual function, all overloads of that base class virtual function should also be...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.