?
Solved

What's the difference between "override" and "overload"?

Posted on 1999-01-25
6
Medium Priority
?
498 Views
Last Modified: 2010-04-16
What's the difference between "override" and "overload"?
0
Comment
Question by:jhoon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 1

Expert Comment

by:Seeker092397
ID: 1185072
The difference i think is in following:

Override is about inheritence: Overriden function is the function defined in both base and derived classes in exactly the same way, it lets you change the bahaviour of base class.

Overload is about the number of functions with the same name: This way you can define a number of functions in one class with the same name but different parameter types.

Hope this helps.
Best regards.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1185073
That's it.    Why don't you answer, seeker?

The way I think about it is that a derived class can provide a finction that overides (changes the behaviour) of a base class's function..  And that two functions with the same and different parameters are overloaded with posibilities.  


0
 

Author Comment

by:jhoon
ID: 1185074
Thank you so much.

Now I know "overload" which enable a program to have polymorphism.

but I'm not clear about "override".

Would you tell me more about "override" including a simple sample code?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Accepted Solution

by:
Seeker092397 earned 200 total points
ID: 1185075
Override example:

class A
{
public:
  A()
  {
    m_nVal = 0;
  }
  void Foo()
  {
    m_nVal = 1;
  }

  int m_nVal;
};

class B : public A
{
public:
  B() : A()
  {}
  void Foo()
  {
    m_nVal = 2;
  }
};

Class B overrides function Foo(). So now calling
B b;
b.Foo();
will set m_mVal to 2 instead of 1.

You do overriding only if you need to. I mean, if your B class is pretty happy with the way A handles Foo() it shouldn't override it(shouldn't define Foo in its class definition) and still you will be able to call b.Foo() but in this case m_nVal will get value 1.

Hope this helps.

Best regards.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1185076
>>Now I know "overload" which enable a program to have polymorphism
No, it is "overide" that provides polymorphism.  Consider a class heirarchy for shapes.  You may have a base class called "Shape", add derive three classes from it for "Circle" "Rectangle", and "Triangle".  Shape may provide a virtual procedure called "Draw()" that is supposed to draw the shape.  (But in the shape class the procedure does nothing, since shape is an abstract class and there is no shape associated with it.)  Each of the derived classes OVERRIDE this procedure to draw their own shapes.   This is polymorphism.  The Shape() function has polymorphic behavior--it acts differently for different classes--because it was overidden.
0
 

Author Comment

by:jhoon
ID: 1185077
Thank you seeker.

You got rid of my ambiguity.

Thanks again.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question