在另一个cpp文件c ++中的一个cpp文件中使用函数变量

时间:2014-04-09 10:17:49

标签: c++ global-variables extern

我使用头文件和extern从一个cpp文件向另一个cpp文件发送变量。问题是文件在到达第二个cpp文件时没有填充。

//Tmp.h 
//Declare tmp_user and tmp_pass
extern ustring tmp_user;
extern ustring tmp_pass;



//TmpOne.cpp
//define tmp_user and tmp_pass
#include "Tmp.h"

ustring tmp_user; //define outside of function
ustring tmp_pass;

function(blah, blah){    
    tmp_user = username; //fill the variable within the function
    tmp_pass = password;
//more code
}



//TmpTwo.cpp
//use the defined variables
#include "Tmp.h"

login(tmp_user, tmp_pass) //Both of the defined variables are empty.
{
    //some function
}

我的问题是,在我的第二个cpp文件中调用时,这两个变量都是空的。我使用的是visual studio 2010,两个cpp文件都在同一个项目中。

0 个答案:

没有答案
相关问题