| | |
Help with C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 16
Reputation:
Solved Threads: 0
I'm looking at this code and I'm not sure what it prints (I don't have a C++ compiler to run it). However, I also would like to understand why it prints what it does? hope someone can help, here's the code:
I guess I'm most interested in knowing what funtion a.r() is going to call since right before we said had a=c. Will it call class A's function or class C's. I have no idea what A* ap = new B will do.
C++ Syntax (Toggle Plain Text)
class A { public: virtual void p() { cout << "A.p" << endl; } void q() { cout << A.q" << endl; } virtual void r () { p(); q(); } }; class B : public A { public: void p() { cout << "B.p" << endl; } }; class C : public B { public: void q() { cout << "C.q" << endl; } void r () { q(); p(); } }; ... A a; C c; a = c; a.r(); A* ap=new B; ap -> r(); ap = new C; ap -> r();
I guess I'm most interested in knowing what funtion a.r() is going to call since right before we said had a=c. Will it call class A's function or class C's. I have no idea what A* ap = new B will do.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Table
- Next Thread: How to generate an uniqe number always?
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector visualstudio win32 windows winsock word wordfrequency wxwidgets






