在C++中,类static变量独立于实际的对象。static变量在类中定义,并且不能附值,需要在类的外面有且仅有定义和初始化静态变量一次。 由于整个类共享静态变量,所以在类外部定义和初始化静态变量时须将其放到任何一个cpp文件中,不能放在.h文件中,否则当多个cpp文件包含h文件时,就会出现对静态变量的多重定义,引起errorLNK2005错误。例如在Compression.h文件中类Compression声明如下:class Compression{private:static set< string >removedRelation;vector< destToken >destSentence;
public:void compression(vector< sourceToken>& sourceSentence);int getDestSentence(string& str);static int initRemovedRelation(const string filename);};

set< string >Compression::removedRelation; 这样在编译时就会出现errorLNK2005错误,因为static变量的定义和初始化与类在同一个文件,当多个文件包含该文件时,就会对该static变量多重定义。所以应该改为:在Compression.h文件中类Compression声明如下:class Compression{private:static set< string >removedRelation;vector< destToken >destSentence;
public:void compression(vector< sourceToken>& sourceSentence);int getDestSentence(string& str);static int initRemovedRelation(const string filename);}; 将set< string >Compression::removedRelation;语句放到cpp文件中,即可编译通过。
爱华网本文地址 » http://www.aihuau.com/a/25101014/219774.html
更多阅读

VSS(Visual SourceSafe)使用方法——简介Visual SourceSafe简介lVSS微软的产品。简单好用,局域网中用VSS。适用于Team级还可以,企业级不好,仅支持Windows操作系统。?Visual SourceSafe是一个源代码控制系统,可以保存文件的不同版本,可以比

1. 批处理脚本批处理脚本就是把一个一个的命令外加一些逻辑控制组合在一起使其可一次都被执行的文本文件。在Linux上为Shell脚本,而在Windows上则为bat脚本。Windows下脚本命令能够执行需要同时满足以下两个条件:路径使用以驱动盘符开

最近做项目需要简单的记录日志,所以决定采用log4net做。在网上看了些例程,都说不是很难,但是实际操作起来还是因为不熟悉有些小问题。在这里把配置过程以及容易出问题的地方分享一下。1. 首先下载log4net的dll链接库下载地址:http://log

冒泡排序就是把小的元素往前调或者把大的元素往后调。比较是相邻的两个元素比较,交换也发生在这两个元素之间。相同元素的前后顺序不会发生变化,冒泡法是一种稳定的排序算法。例如:inta[10]={3,7,2,4,5,8,9,0,6,1};size_tn=sizeof

字体安装--------------------------复制 word中钢筋直径符号使用.ttf 到C:WINDOWSFonts----------------------------如何使用--------------------------比如。某处要显示 钢筋符号。比如在 excel中。 对单元格的 字