473,320 Members | 1,863 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,320 software developers and data experts.

overload & and inheritance problem


I have a maybe a "noob" question to ask but I'd like to why that code does
not compile and why more precisely it does not search for 'print()' method
in 'Model'.
Of course I could replace 'print()' by 'write()' but I'm stubborn.

#include <iostream>

using namespace std;

struct Model {
virtual void print(ostream &o)=0;
void print() { print(cout); }
};

struct Subclass : public Model {
void print(ostream& o)
{
o << "Subclass";
}

};

int main()
{
Subclass c;

c.print();
}


Thanks for any help.
Jul 22 '05 #1
2 1374
Vincent ROGER wrote:
I have a maybe a "noob" question to ask but I'd like to why that code
does not compile and why more precisely it does not search for
'print()' method in 'Model'.
Of course I could replace 'print()' by 'write()' but I'm stubborn.
Subclass::print(ostream&) hides Model::print(). See below.

#include <iostream>

using namespace std;

struct Model {
virtual void print(ostream &o)=0;
void print() { print(cout); }
};

struct Subclass : public Model {
void print(ostream& o)
{
o << "Subclass";
}
Add

using Model::print;

};

int main()
{
Subclass c;

c.print();
}

Thanks for any help.


Anytime.

V
Jul 22 '05 #2

Thank you for both the explanation and the solution.
Seems like C++ will always be able to surprise me.
Jul 22 '05 #3

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

Similar topics

0
by: Alice Bag | last post by:
groovy feature request: I think comments on COLUMNs should be inherited from the "parent" table when the "child" table is created. If you make use of inheritance, this would be a big time...
10
by: Benny Raymond | last post by:
I'm trying to change the way a treeview works just a bit, i'm pretty new to C# and now i'm running into overloading. I tried the following code and it's yelling at me saying that no overload...
13
by: Vladimir Granitsky | last post by:
Hi guys, Please, look at the code below and try to step into it. The compiled code calls the loosely typed method public void Method1(object o) !?!? Am I right that C# compiler does wrong...
7
by: Dmitry Shuklin | last post by:
I am compiled my C file into IL source, How i can compile this file back to OBJ file, not to EXE or DLL? or, can i compile to OBJ file VB or C# code and link them with C++ managed OBJ files? ...
5
by: Mike Labosh | last post by:
In VB 6, the Form_QueryUnload event had an UnloadMode parameter that let me find out *why* a form is unloading, and then conditionally cancel the event. In VB.NET, the Closing event passes a...
3
by: Trammel | last post by:
Hi, I recently upgraded to VB.net from VB6.. and woah... I feel lost :¬O One of my reasons for upgrading is I was told that VB.net can do class inheritance and subclassing easier. ...
5
by: dragon | last post by:
error! 33 E:\program\wukexin\file\file.h `bool My_lib::Cfileinfo::initialize(const char*)' is private 19 E:\program\wukexin\dir\dir.cpp within this context ////////////////////////////////////...
3
by: needin4mation | last post by:
The code is taken from the book Professional C#: abstract class GenericCustomer { private string name; public GenericCustomer(string name) { this.name = name; }...
42
by: coder_lol | last post by:
Thanks everyone again for contributing to helping me clear C++ confusions. I did some serious reading on copy constructors and assignments and I think I've got a good handle on the memory stuff. ...
3
by: epanda | last post by:
Hi, I would like to merge two class which have got 90% of same source code. But I don't know what to do. class A { int putLightOn () { switch(status)
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.