概要:3、用途不同。通常在复制字符串时用strcpy,而需要复制其他类型数据时则一般用memcpy。10、请写出以下程序的输出结果class Base{public:Base(){printf("I am Base()\n");}virtual ~Base(){printf("I am ~Base()\n");}public:virtual void SayHello(){printf("Hello Base\n");}void SayWorld(){printf("World Base\n");}};class Derived : public Base{public:Derived(){printf("I am Derived()\n");}virtual ~Derived(){printf("I am ~Derived()\n");}public:void SayHello();void SayWorld();};void Derived::Say
2017年海康威视校园招聘笔试题,标签:笔试大全,http://www.88haoxue.com3、用途不同。通常在复制字符串时用strcpy,而需要复制其他类型数据时则一般用memcpy。
10、请写出以下程序的输出结果
class Base
{
public:
Base()
{
printf("I am Base()\n");
}
virtual ~Base()
{
printf("I am ~Base()\n");
}
public:
virtual void SayHello()
{
printf("Hello Base\n");
}
void SayWorld()
{
printf("World Base\n");
}
};
class Derived : public Base
{
public:
Derived()
{
printf("I am Derived()\n");
}
virtual ~Derived()
{
printf("I am ~Derived()\n");
}
public:
void SayHello();
void SayWorld();
};
void Derived::SayHello()
{
printf("Hello Derived\n");
}
void Derived::SayWorld()
{
printf("World Derived\n");
}
int main(void)
{
Base *b1 = new Base;
Base *b2 = new Derived;
Derived *d = new Derived;
b1->SayHello();
b1->SayWorld();
b2->SayHello();
b2->SayWorld();
d->SayHello();
d->SayWorld();
delete d;
delete b2;
delete b1;
d= NULL;
b2 = NULL;
b1 = NULL;
return 0;
}
class Base
{
public:
Base()
{
printf("I am Base()\n");
}
virtual ~Base()
{
printf("I am ~Base()\n");
}
public:
virtual void SayHello()
{
printf("Hello Base\n");
}
void SayWorld()
{
printf("World Base\n");
}
};
class Derived : public Base
{
public:
Derived()
{
printf("I am Derived()\n");
}
virtual ~Derived()
{
printf("I am ~Derived()\n");
}
public:
void SayHello();
void SayWorld();
};
void Derived::SayHello()
{
printf("Hello Derived\n");
}
void Derived::SayWorld()
{
printf("World Derived\n");
}
int main(void)
{
Base *b1 = new Base;
Base *b2 = new Derived;
Derived *d = new Derived;
b1->SayHello();
b1->SayWorld();
b2->SayHello();
b2->SayWorld();
d->SayHello();
d->SayWorld();
delete d;
delete b2;
delete b1;
d= NULL;
b2 = NULL;
b1 = NULL;
return 0;
}输出结果:
I am Base()
I am Base()
I am Derived()
I am Base()
I am Derived()
Hello Base
World Base
Hello Derived
World Base
Hello Derived
World Derived
I am ~Derived()
I am ~Base()
I am ~Derived()
I am ~Base()
I am ~Base()
11、阅读以下程序并给出执行结果
class Bclass
{
public:
Bclass(int i , int j)
{
x = i;
y = j;
}
virtual int fun()
{
return 0;
}
protected:
int x , y;
};
class lclass : public Bclass
{
public:
lclass(int i , int j , int k) : Bclass(i , j)
{
z = k;
}
int fun()
{
return (x+y+z)/3;
}
private:
int z;
};
int main(void)
{
lclass obj(2,4,10);
Bclass p1 = obj;
cout<
Bclass &p2 = obj;
cout<
cout<
Bclass *p3 = &obj;
cout
return 0;
}
class Bclass
{
public:
Bclass(int i , int j)
{
x = i;
y = j;
}
virtual int fun()
{
return 0;
}
protected:
int x , y;
};
最新更新