-
Notifications
You must be signed in to change notification settings - Fork 0
/
hidebase.cpp
43 lines (39 loc) · 1.17 KB
/
hidebase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*************************************************************************
# File Name: hidebase.cpp
# Author: alanzfduan
# mail: [email protected]
# Created Time: Tue 24 Jan 2017 06:39:22 AM PST
************************************************************************/
#include<iostream>
using namespace std;
class hideBase
{
public:
virtual void print()
{
std::cout<<"i am base"<<std::endl;
return;
}
};
class hideDrived:public hideBase
{
public:
virtual void print(int x)
{
std::cout<<"i am derived"<<std::endl;
return;
}
};
int main(int argc,char * argv[])
{
// 1 this will pass the compile progress
// because in the base class it finds a function named print without parameter
// Note: the name lookup starts with the declared type not the true type(from new)
hideBase *p = new hideDrived();
p->print();
// 2 this will fail because in the derived class it can not find a function named print without parameter(it will find
// a print function with a int param)
hideDrived *q = new hideDrived();
q->print();
return 0;
}