C++一个小程序按照讲座上打出来的 但是不能执行

[复制链接]
查看11 | 回复1 | 2010-6-6 10:56:24 | 显示全部楼层 |阅读模式
此题代码如下 用到了给常量初始化的方法 请各位看看怎么样能让程序运行起来 不胜感激!
#include
using namespace std;
class A
{
A(int i);
void print();
const int& r;
private:
const int a;
static const int b;
};
const int A::b=10;
A::A(int i):a(i),r(a){}
void A::print()
{
cout<<a<<":"<using namespace std;class A{public: A(int i); void print(); const int& r;private: const int a; static const int b;};const int A::b=10;A::A(int i):a(i),r(a){}void A::print(){ cout<<a<<":"<<b<<":"<<r<<endl;}void main(){ A a1(100),a2(0); a1.print(); a2.print();
回复

使用道具 举报

千问 | 2010-6-6 10:56:24 | 显示全部楼层
class A{public: //这一行不可以少 A(int i); void print(); const int& r;private: const int a; static const int b;};
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行