473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ansi status of 'using'

Dear Colleagues

re: 'using' and the ANSI C++ standard

According to the ANSI C++ standard, is this a valid
way (disregarding whether it is 'naughty') of converting a
public method in the base class into a private method in the child class?
My g++ compiler ignores this without comment.

class parent{
public:
double length(double num) {return num; }
};

class child: public parent {
public:
double hiding(double num) {return length(num);}
private:
using parent::length;
};

ie, equivalent to:
private:
double length(double num) {return parent::length(num); }

Mark Huppert

Jul 22 '05 #1
4 1314

"Mark Huppert" <du******@netspeed.com.au> wrote in message
news:40********@mail.netspeed.com.au...
Dear Colleagues

re: 'using' and the ANSI C++ standard

According to the ANSI C++ standard, is this a valid
way (disregarding whether it is 'naughty') of converting a
public method in the base class into a private method in the child class?
My g++ compiler ignores this without comment.

class parent{
public:
double length(double num) {return num; }
};

class child: public parent {
public:
double hiding(double num) {return length(num);}
private:
using parent::length;
};

ie, equivalent to:
private:
double length(double num) {return parent::length(num); }

No, but why doing this? You can do:
class parent{
public:
double length(double num) {return num; }
};

class child: private parent {
public:
double hiding(double num) {return length(num);}
};


Regards,

Ioannis Vranos

Jul 22 '05 #2
Mark Huppert wrote:
According to the ANSI C++ standard, is this a valid
way (disregarding whether it is 'naughty') of converting a
public method in the base class into a private method in the child class?
No.
My g++ compiler ignores this without comment.
Because it's doing something valid, just not what you think it's doing.
class parent{
public:
double length(double num) {return num; }
};

class child: public parent {
public:
double hiding(double num) {return length(num);}
private:
using parent::length;
};

ie, equivalent to:
private:
double length(double num) {return parent::length(num); }

Are you sure about that? There is no way to make publicly inherited
members "more private." Try this.

class parent{
public:
double length(double num) {return num; }
};

class child: public parent {
public:
double hiding(double num) {return length(num);}
private:
using parent::length;
};

int main ( )
{
child c;

c.length( 3.0 );
}
Jul 22 '05 #3
Mark Huppert wrote:
Dear Colleagues

re: 'using' and the ANSI C++ standard

According to the ANSI C++ standard, is this a valid
way (disregarding whether it is 'naughty') of converting a
public method in the base class into a private method in the child class?
My g++ compiler ignores this without comment.

class parent{
public:
double length(double num) {return num; }
};

class child: public parent {
public:
double hiding(double num) {return length(num);}
private:
using parent::length;
};

ie, equivalent to:
private:
double length(double num) {return parent::length(num); }


The using declaration does "bring the otherwise hidden names
from the base class into scope of the derived class", but I don't
think it does matter whether you put it in the private or protected
or public section. Therefore I'd say it is *not* equivalent.

Hope I got it right this time :)

You could visit
http://www.parashift.com/c++-faq-lit....html#faq-23.6
for an example of meaningful usage of 'using' within a class.

HTH,
- J.
Jul 22 '05 #4
"Mark Huppert" <du******@netspeed.com.au> wrote in message
news:40********@mail.netspeed.com.au...
Dear Colleagues

re: 'using' and the ANSI C++ standard

According to the ANSI C++ standard, is this a valid
way (disregarding whether it is 'naughty') of converting a
public method in the base class into a private method in the child class?
My g++ compiler ignores this without comment. [...]

'using' can only *increase* the visibility of an inherited member
(i.e. make a private member public), but not restrict it.
class parent{
public:
double length(double num) {return num; }
};

class child: public parent {
public:
double hiding(double num) {return length(num);}
private:
using parent::length;
};


You cannot do this, and it wouldn't really make sense:
child c;
c.length(); // you want this to be an error?
parent& p = c; // but this is legal and implicit
p.length(); // legal, and no cast needed...

What you can do is privately derive from parent.
Or even better, use *containment* instead
(store child as a data member of parent).
Regards,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- e-mail contact form
Brainbench MVP for C++ <> http://www.brainbench.com
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Eric Myers | last post by:
Hello folks: (This message is also posted on the help forum at the pexpect sourceforge page, but all indentation in the code got stripped away when I submitted the post.) For some time I've...
3
by: ColdCanuck | last post by:
Help! I'm trying to understand the new ANSI join syntax (after many years of coding using the old style). I am now working with an application that only understands ANSI syntax so I am...
100
by: Roose | last post by:
Just to make a tangential point here, in case anyone new to C doesn't understand what all these flame wars are about. Shorthand title: "My boss would fire me if I wrote 100% ANSI C code" We...
11
by: Nicholas R. Markham | last post by:
When I compile with the -ansi option (using gcc 3.2.3) I'm warned of an implicit declaration of function 'finite'. Does this mean that finite() is not part of ANSI C, or that I didn't include a...
48
by: Daniele C. | last post by:
As soon as my sourceforge.net project gets approved, I am going to build a ncurses port to win32 bindable to sockets, e.g. allowing VT100/ANSI terminals and the creation of simple terminal servers...
1
by: Jimmy Stewart | last post by:
the character map that comes with windows only gives keystrokes in unicode and not ansi (i.e. alt+####) what gives. How can I use those codes to insert special characters. Also, why cant I copy an...
0
by: MaartenVR | last post by:
sub: MS SQL server and (missing) ANSI DATE-datatype I’m working at a company who has developed a large client/server application in Delphi 6, with Interbase as the DB-server (both Borland...
4
by: candide_sh | last post by:
Hello, I created a script with database publishing wizard to convert a SS2005 db into a SS2k db. The script has schema and data and looks very good. When I try to start the created script in...
0
NeoPa
by: NeoPa | last post by:
ANSI-89 v ANSI-92 Before we get into all the various types of pattern matching that can be used, there are two ANSI standards used for the main types of wildcard matching (matching zero or more...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.