全局变量啊 全局变量
有如下宏定义:(两个宏定义在同一个头文件中)
//////////////////////////////////////////////////////////////////////
#define beginM(func) \
private: \
static void pStr() \
{ \
#define M(sourceline){ \std::string anStr1(sourceline); \
}
#define endM \
} \
public:
//////////////////////////////////////////////////////////////////////
#define beginN(func) \
private: \
static void func(std::string & Nstring) \
{
#define N(sourceline){ \std::string anStr2(sourceline); \
}
#define endN \
} \
public:
怎样把第一个宏中的anStr1传到第二个宏中去?使得第二个宏中也能使用到anStr1?
全局变量可以吗?
我定义了extern std::string gVal;
然后gVal=anStr1;
在第二个宏中用的时候有链接错误
指教!!!!! 谢谢!
[解决办法]
感觉你第一个宏没写全嘛,至少没看到beginM(func)中的func在哪儿展开.
//当你在类中写下
class X
{
......
beginM(func)
M( "message ")
endM
......
};
展开后,在static函数pStr中定义了一个anStr1局部变量.在其他函数中根本没法使用.
extern 是针对全局变量的.