标题:[原创]声明和使用虚函数
只看楼主
zhangzujin
Rank: 1
等 级:新手上路
帖 子:276
专家分:0
注 册:2005-5-9
 问题点数:0 回复次数:1 
[原创]声明和使用虚函数

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

__gc class parent
{
protected:
int x;
public:
parent(int a) // 带参数的虚函数
{
x=a;
};
virtual void ShowX( )=0; // 纯虚函数
};

__gc class son1:public parent
{
public:
son1(int a):parent(a)
{
};
void ShowX( )
{
Console::Write(S"Method1's show X:");
Console::WriteLine(x);
};
};

__gc class son2:public parent
{
public:
son2(int a):parent(a)
{
};
void ShowX( )
{
Console::Write(S"Method2's show X:");
Console::WriteLine(x);
};
};

int _tmain()
{
son1 *sonA;
son2 *sonB;

sonA=new son1(1);
sonB=new son2(2);
sonA->ShowX( );
sonB->ShowX( );

return 0;
}

搜索更多相关主题的帖子: 函数 声明 
2006-01-11 21:31
zhangzujin
Rank: 1
等 级:新手上路
帖 子:276
专家分:0
注 册:2005-5-9
得分:0 
回复
9SatYdz8.rar (994.78 KB) [原创]声明和使用虚函数



太极之道 qq:283421560 E-mail:zhangzujin360732@
2006-01-11 21:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-42489-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 2.372782 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved