静态常成员变量运用

// test.h

class C{
public:
 static const int M;
};
const int C::M = 12;

// test.cpp
#include "stdafx.h"
void fun(){
 cout << C::M << endl;
}

// main.cpp
#include "stdafx.h"
#include "test.h"


void fun();

int main(){
 fun();
}

// 会出错, 静态常成员变量必须在静态联编的时候解析,而调用fun本就是【另外一个文件中】的函数,因此在link的时候解析,如

果把fun调到main中,则可以正常运行.

posted on 2011-10-02 11:03 メmarsメ 阅读(346) 评论(0)  编辑 收藏 引用 所属分类: Single View


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2011年10月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

导航

统计

常用链接

留言簿

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜