---------
typedef struct {int i;} somestruct;
class A
{
public:
A() {}
bool read(char* ptr, int len);
// bool read2(char* ptr, int len); // 1.
};
class B : public A
{
public:
B() {}
bool read(somestruct* s) {return read((char*)s, (int)sizeof(*s));}
// bool read(somestruct* s) {return read2((char*)s, (int)sizeof(*s));} // 1.
// bool read(somestruct* s) {return A::read((char*)s, (int)sizeof(*s));} //
2.
};
----------
A::read was inherited and should be in scope with B::read, but the compiler
still can't find it. I have even casted the second argument to int, but it
didn't help either, hehe... If I rename A::read to A::read2 and call read2
(1), or if I call A::read(...) by specifying the scope (2) then it works,
but it is pretty inconvinient and unnecessarily looking to my opinion. I
suspect there is a standard compliance behind this, but what is the reason
disallowing this kind of code? And why is it case so different from the
following piece of (compiling) code? (please ignore that ptr is pointing to
nowhere :)
----------
typedef struct {int i;} somestruct;
bool read(char* ptr, int len);
bool read(somestruct* s) {return read((BYTE*)s, sizeof(*s));}
void somefunct()
{
char* ptr;
read(ptr, 1);
somestruct s;
read(&s);
}
---------- 2 1008
Because C++ uses "hide by name" rules instead of "hide by signature". The
definition of read in class B makes all definitions of read in base classes
hidden.
Use a "using declaration" to get the behavior you want.
class B : public A
{
public:
B() {}
using A::read;
bool read(somestruct* s) {return read((char*)s, (int)sizeof(*s));
}
Ronald Laeremans
Visual C++ team
"Gabest" <ga****@freemail.hu> wrote in message
news:ez**************@TK2MSFTNGP12.phx.gbl... ---------
typedef struct {int i;} somestruct;
class A { public: A() {} bool read(char* ptr, int len); // bool read2(char* ptr, int len); // 1. };
class B : public A { public: B() {} bool read(somestruct* s) {return read((char*)s, (int)sizeof(*s));} // bool read(somestruct* s) {return read2((char*)s, (int)sizeof(*s));} //
1. // bool read(somestruct* s) {return A::read((char*)s, (int)sizeof(*s));}
// 2. };
----------
A::read was inherited and should be in scope with B::read, but the
compiler still can't find it. I have even casted the second argument to int, but it didn't help either, hehe... If I rename A::read to A::read2 and call read2 (1), or if I call A::read(...) by specifying the scope (2) then it works, but it is pretty inconvinient and unnecessarily looking to my opinion. I suspect there is a standard compliance behind this, but what is the reason disallowing this kind of code? And why is it case so different from the following piece of (compiling) code? (please ignore that ptr is pointing
to nowhere :)
----------
typedef struct {int i;} somestruct;
bool read(char* ptr, int len); bool read(somestruct* s) {return read((BYTE*)s, sizeof(*s));}
void somefunct() { char* ptr; read(ptr, 1); somestruct s; read(&s); }
----------
"Ronald Laeremans [MSFT]" <ro*****@online.microsoft.com> wrote in message news:<Oz**************@TK2MSFTNGP10.phx.gbl>... Because C++ uses "hide by name" rules instead of "hide by signature". The definition of read in class B makes all definitions of read in base classes hidden.
Use a "using declaration" to get the behavior you want.
class B : public A { public: B() {} using A::read; bool read(somestruct* s) {return read((char*)s, (int)sizeof(*s)); }
Ronald Laeremans Visual C++ team
Thanks, I had absolutely no idea about this "using" keyword before! I
guess it is never late to learn something new. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: penguinman |
last post by:
Its just a hello world program.
Compile and build goes with no warning or error.
i type ./a.out and the shell just sits there. It doesnt hang but it
just sits there with no output.
I executed...
|
by: penguinman |
last post by:
I type ./a.out and the shell just sits there. It doesnt hang it just
sits there looking pretty.
I run the program with the ddd option and executed it from
ddd...execution window comes up and...
|
by: Zardoz |
last post by:
Hi,
I'm trying to find a workaround to this problem
ON_BN_CLICKED(IDC_CANCEL, OnCancelOperation)
BOOL CCurrenciesDialog::OnCancelOperation()
|
by: manokumar |
last post by:
hiye, i notice that some if not all of my folders in winxp
pro. are set as read only and its giving me some problem
with development. so as the natural thing, i unchecked the
read only option and...
|
by: dhnriverside |
last post by:
HI guys
I've just written my first independent namespace for my library (yay me!).
However, on trying to add it to my website project, it causes an error when I
look at the website. It compiles...
|
by: lumpybanana247 |
last post by:
this will compile with no errors, debug no errors- just doesnt really do any thing when it runs
#include <iostream>
using namespace std;
void calculate(int a,int b,int& c); //you need to...
|
by: kal |
last post by:
I have registered my custom control in web.config as follows:
<add tagPrefix="PhoenixControls" namespace="PhoenixControls"
assembly="PhoenixControls"/>
I have added a file called...
|
by: =?Utf-8?B?SlA=?= |
last post by:
<asp:GridView ID="gridResults" runat="server" AutoGenerateColumns="False"
Width="98%" PageSize="25" AllowPaging="True" OnSorting="gridResults_Sorting"
OnPageIndexChanging...
|
by: alan75 |
last post by:
After i've build the exe files and everything, I copied all files to another PC, remembering to also copy the required DLLs and registering them.
The error message when trying to run the program...
|
by: H1TM4N |
last post by:
can someone help? Its the following code it just wont compile
thanks :)
PROGRAM Store (INPUT, OUTPUT);
VAR
Change, AmountPaid, TotalPrice :REAL;
IntChange, Dollars, Quarters, Dimes,...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |