如何在没有包含总.h文件的命名空间内声明一个类? [英] how to declare a class inside a namespace without include total .h file?

查看:80
本文介绍了如何在没有包含总.h文件的命名空间内声明一个类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如上所述!

由于很多原因,我们只是简单地声明一些类而不是在主.h文件中包含总接口头文件(如果没有获取,例如该类实例为班级成员等)。



我们都知道,要宣布一个班级很简单。只是

   class xml_document 





但是类xml_document是驻留命名空间pugi。



如何完成它?

我有trie:

 名称空间 pugi; 
class pugi :: xml_document;
pugi :: xml_document& amp; getXmlDoc() const ;





但编译器对第一行有所了解。谢谢

解决方案

您的语法不正确,您需要在类的开头和结尾使用块标识符,如:

 命名空间 pugi  //  启动命名空间定义 
{
class xml_document // 开始课程定义
{
xml_document& getXmlDoc() const ;

} // 课程定义结束

} // 命名空间定义结束

删除分号:

 命名空间 SomeLib 
{
< span class =code-keyword> class String {...};
}



请参阅: http ://msdn.microsoft.com/en-us/library/5cb46ksf.aspx [ ^ ]


我找到了答案!谢谢!



http://www.devx。 COM /提示/提示/ 32118

like mention above!
For many reasons , we just to simple declare some classes rather include total interface header file in the main .h file(if that's not acquired,e.g that class instance as the class member etc).

we all know,To just declare a class is simple. just

"class xml_document"



but while the class xml_document is reside namespace pugi.

How can I accomplish it?
I have trie :

namespace pugi;
class pugi::xml_document;
pugi::xml_document &amp; getXmlDoc()const; 



but compiler compain about the first line. thanks

解决方案

Your syntax is not correct, you need to use block identifiers at the beginning and end of the class and the namespace, like:

namespace pugi // start namespace definition
{
    class xml_document // start class definition
    {
        xml_document& getXmlDoc()const;

    } // end of class definition

} // end of namespace definition


Remove the semicolon:

namespace SomeLib
   {
   class String { ... };
   }


See here: http://msdn.microsoft.com/en-us/library/5cb46ksf.aspx[^]


I have find the answer! thanks any way!

http://www.devx.com/tips/Tip/32118


这篇关于如何在没有包含总.h文件的命名空间内声明一个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆