realy i did not understand that what function over riding means
can any body help me for that please

Recommended Answers

All 3 Replies

realy i did not understand that what function over riding means
can any body help me for that please

A) Use google or Daniweb Search
B) Say you have a function that you want to work on both strings and chars for example I have a function to convert a decimal number to a binary string (Hi -> 0100100001101001)

string decbin(char a)
{
  string dest;
  int rem = a;
  for (int i = 7; i >= 0; i--) {
    dest += (rem / (1 << i)) ? '1' : '0';
    rem %= (1 << i);
  }
  return dest;
}

string decbin(string* inp)
{
  string result = "";
  for (unsigned int i = 0; i < inp->length(); i++) {
    result += decbin((*inp)[i]);
  }
  return result;
}

So I have two functions, both which have the same name, but based on the TYPE of the parameter passed do two separate things, ie.,

char mychar = 'a';
string mystring = "Hello World";
string mycharbin = decbin(mychar); // calls decbin(char)
string mystringbin = decbin(mystring); // calls decbin(string)

So I have two functions, both which have the same name, but based on the TYPE of the parameter passed do two separate things

You described function overloading, not overriding. Overriding is replacing the implementation of a method with a specialized implementation in a derived class.

You described function overloading, not overriding. Overriding is replacing the implementation of a method with a specialized implementation in a derived class.

I hate when I brain changes words in sentences without telling me, in my defense I use the word method for class methods only and functions for globally namespaced functions

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.