PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Inheritence and function overloading
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Inheritence and function overloading

Réponse
 
LinkBack Outils de la discussion
Vieux 08/02/2008, 09h09   #1
ambarish.mitra@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Inheritence and function overloading

Class A has a public method f, and another class B is publicly derived
from A. The derived class B has also the same function but with
different arguments.

Question: In the scope of class B, is the function f overloaded? (yes/
no)


class A
{
public: int f(int x);
}

class B: public A
{
public: int f(int x, float y);
}

  Réponse avec citation
Vieux 08/02/2008, 09h21   #2
Kira Yamato
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Inheritence and function overloading

On 2008-02-08 04:09:26 -0500, ambarish.mitra@gmail.com said:

> Class A has a public method f, and another class B is publicly derived
> from A. The derived class B has also the same function but with
> different arguments.
>
> Question: In the scope of class B, is the function f overloaded? (yes/
> no)
>
>
> class A
> {
> public: int f(int x);
> }
>
> class B: public A
> {
> public: int f(int x, float y);
> }


To see if it is overloaded or not, why not try to write some code to test it?

More specifically, try invoking f(1) and f(1,1.) on an B object.

--

// kira

  Réponse avec citation
Vieux 08/02/2008, 10h43   #3
ltcmelo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Inheritence and function overloading

On Feb 8, 6:09am, ambarish.mi...@gmail.com wrote:
> Class A has a public method f, and another class B is publicly derived
> from A. The derived class B has also the same function but with
> different arguments.
>
> Question: In the scope of class B, is the function f overloaded? (yes/
> no)
>
> class A
> {
> public: int f(int x);
>
> }
>
> class B: public A
> {
> public: int f(int x, float y);
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -


Hi.

In this case it's not an overload because the implementation in B
hides the implementation in A. Basically, C++ lookup rules will try to
find the symbol in class B. Since it'll find it, class A won't be
looked up.


Leandro Melo
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h09.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09951 seconds with 11 queries