GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-May-2008, 09:32
khushal_kkk's Avatar
khushal_kkk khushal_kkk is offline
Junior Member
 
Join Date: Mar 2008
Posts: 42
khushal_kkk is on a distinguished road
Exclamation

need help in OOP In C++


what is an operator overloading and how it is used in a class can u give me an example of a distance by explaining through a program code....
__________________
K K K
  #2  
Old 15-May-2008, 20:00
ocicat ocicat is offline
Member
 
Join Date: May 2008
Posts: 203
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: need help in OOP In C++


Quote:
Originally Posted by khushal_kkk
what is an operator overloading and how it is used in a class can u give me an example of a distance by explaining through a program code....
I don't know what you mean by distance, but the following is an example of overloading:
Code:
$ cat overloading.cpp
CPP / C++ / C Code:
#include <iostream>

using namespace std;

class foo {
    int v;
public:
    foo(int i)  { v = i; }
    int value() const  { return v; }
};

ostream& operator<<(ostream&, const foo&);

int
main() {
    foo f(8);

    cout << f << endl;

    return 0;
}

ostream&
operator<<(ostream &out, const foo &f) {
    return out << "(" << f.value() << ")";;
}
$ g++ -Wall overloading.cpp $ ./a.out (8) $
Enjoy.
Last edited by LuciWiz : 21-May-2008 at 00:39. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #3  
Old 18-May-2008, 03:00
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 434
Peter_APIIT is an unknown quantity at this point

Re: need help in OOP In C++


Overloading is a terminology where several same function name has different signature.
 
 

Recent GIDBlogHalfway done! by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 23:11.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.