public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* public method hidden by protected one
@ 2007-11-26 11:42 Francois Coulon
  2007-11-26 12:48 ` John Love-Jensen
  0 siblings, 1 reply; 4+ messages in thread
From: Francois Coulon @ 2007-11-26 11:42 UTC (permalink / raw)
  To: gcc-help

We have thos two declarations in a class :

public:
    const DonneesCP & getDonneesCP() const ;

protected:
   DonneesCP &getDonneesCP();

We try to call the public one from outside the class, we have this error :

/vobs/ERATO/SMET/SAD/PUB/Linux-x86_64/include/DonneesCP/InterfaceDonneesCP.hpp:320:
error: « erato::DonneesCP& erato::InterfaceDonneesCP::getDonneesCP() »
is protected
/vobs/ERATO/APP/OTDA/TUFA/src/TUFA/tuf.cpp:117: error: within this context

If we remove the protected method, the error dissappears.

Is this normal behaviour or not ?

Thanks in advance

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: public method hidden by protected one
  2007-11-26 11:42 public method hidden by protected one Francois Coulon
@ 2007-11-26 12:48 ` John Love-Jensen
  2007-11-26 13:12   ` Francois Coulon
  0 siblings, 1 reply; 4+ messages in thread
From: John Love-Jensen @ 2007-11-26 12:48 UTC (permalink / raw)
  To: Francois Coulon, MSX to GCC

Hi Francois,

Works for me.

Are you sure you are calling getDonneesCP with a const object?

> Is this normal behaviour or not ?

If you are calling getDonneesCP with a non-const object, then it is normal
behavior.

If you are calling getDonneesCP with a const object, then something is
suspicious.

Sincerely,
--Eljay

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: public method hidden by protected one
  2007-11-26 12:48 ` John Love-Jensen
@ 2007-11-26 13:12   ` Francois Coulon
  2007-11-26 16:00     ` John Love-Jensen
  0 siblings, 1 reply; 4+ messages in thread
From: Francois Coulon @ 2007-11-26 13:12 UTC (permalink / raw)
  To: John Love-Jensen; +Cc: MSX to GCC

Hi,

we call it like that :
   DonneesCP dcp = InterfaceDonneesCP_OC::instance()->getDonneesCP();

The method "instance" returns a InterfaceDonneesCP_OC* (non const)

But why should this prevent from calling a const method ?

Additionnal informations :
  InterfaceDonneesCP_OC inherits (public) InterfaceDonneesCP where the
two getDonneesCP are defined.

François

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: public method hidden by protected one
  2007-11-26 13:12   ` Francois Coulon
@ 2007-11-26 16:00     ` John Love-Jensen
  0 siblings, 0 replies; 4+ messages in thread
From: John Love-Jensen @ 2007-11-26 16:00 UTC (permalink / raw)
  To: Francois Coulon; +Cc: MSX to GCC

Hi François,

> But why should this prevent from calling a const method ?

Because it's a non-const pointer, and there is a non-const method which is
an exact unambiguous signature match, and that non-const method has
protected accessibility.

Add a const_instance method that returns a const pointer, and then use that.

Or don't overload the same method name with different accessibility.

Or don't overload the same method name at all, rather have different named
methods.  (This is the option that I think is best, because it is obvious to
me that the two methods are not conceptually the "same thing" for which
overloading is appropriate.  They are different things, strongly indicated
by them having different accessibility.)

HTH,
--Eljay


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-11-26 13:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-26 11:42 public method hidden by protected one Francois Coulon
2007-11-26 12:48 ` John Love-Jensen
2007-11-26 13:12   ` Francois Coulon
2007-11-26 16:00     ` John Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).