+ -
当前位置:首页 → 问答吧 → C++命名空间

C++命名空间

时间:2011-12-21

来源:互联网

C/C++ code


#include<iostream>
#include"hh.h"
using namespace std;
using namespace nspace;
void main()
{
sstruct a;   [color=#00FF00]//此时没有错误[/color]
a.aa=12; [color=#00FF00]//报错   为什麽?[/color]
    
    
    cout<<aint;   [color=#00FF00]//没有错误[/color]    cin.get();
    
}





头文件:C/C++ code

#ifndef a
#define a
namespace nspace
{

    const int aint=30;
    struct sstruct
    {
    int aa;
    char b;
    std::string str;
    
    
    };


}

#endif

作者: zhifeiya   发布时间: 2011-12-21

我的问题是:能在c.cpp中c创建一个结构 但不能对结构成员赋值!sstruct a={.. , .. , ..};也错!

作者: zhifeiya   发布时间: 2011-12-21

#ifndef a

宏的定义名字和sstruct a;的名字重复了。

你把编译器搞蒙了。

建议宏要用大写的。

作者: zhongguoren666   发布时间: 2011-12-21

nspace::

作者: Binzo   发布时间: 2011-12-21