C++_overloading - Overloading occurs when the same operator...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 332: C++ Overloading Overview of C++ Overloading Overloading occurs when the same operator or function name is used with different signatures Both operators and functions can be overloaded Different definitions must be distinguished by their signatures (otherwise which to call is ambiguous) Reminder: signature is the operator/function name and the ordered list of its argument types E.g., add(int,long) and add(long,int) have different signatures E.g., and have different signatures, even if Derived is-a Base Most specific match is used to select which one to call
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSE 332: C++ Overloading Overloading vs. Overriding Overriding a base class method is similar to overloading But definitions are distinguished by their scopes rather than by their signatures C++ can distinguish method definitions according to either static or dynamic type Depends on whether a method is virtual or not Depends on whether called via a reference or pointer vs. directly on an object Depends on whether the call states the scope explicitly (e.g., Foo::baz(); )
Background image of page 2
CSE 332: C++ Overloading Function Overloading class A { public: int add(int i, int j); // not allowed, would be // ambiguous with above // long add(int m, int n); // Ok, different signature long add(long m, long n); }; int main (int argc, char **argv) { int a = 7;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/03/2010 for the course CSE 332S taught by Professor Smart during the Spring '08 term at Washington University in St. Louis.

Page1 / 8

C++_overloading - Overloading occurs when the same operator...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online