在构造函数中初始化变量 [英] initialise variables in constructor
本文介绍了在构造函数中初始化变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨!
我要设计一个mfc应用程序,我在其中创建一个常见的cpp类包含头文件,我在我的项目中包含了所有子文件中的头文件。使用公共访问说明符声明该头文件中的变量,但是当我要在子文件中定义由extern关键字主持的变量时,但是没有访问&将错误视为
错误 LNK2001:未解析的外部符号 void * i_acc_no(?i_acc_no @@ 3PAXA)Add_account.obj
那么如何解决这个问题?
解决方案
您需要在一个代码文件中声明并初始化它们。类似于:
// main.cpp
extern className :: variableName = 0 ;
Hi!
I am going to design one mfc application in which I make one common cpp class contains header file with that,I include that header file in all subfiles in my project & declare variables in that header file with public access specifier,but when I am going to define that variable presided by extern keyword in sub files,but it not accessed & give error as
error LNK2001: unresolved external symbol "void * i_acc_no" (?i_acc_no@@3PAXA) Add_account.obj
so how to solve that problem??
解决方案
You need to declare and initialise them in one code file. Something like:
// main.cpp extern className::variableName = 0;
这篇关于在构造函数中初始化变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文