Tag: 命名空间的

为什么C ++的朋友类只需要在其他命名空间中进行前向声明?

假设我有一个F类,它应该是类G (在全局命名空间)和C (在命名空间A )中的朋友。 要成为A::C朋友, F必须被转发声明。 对G朋友,没有F前向声明是必要的。 同样,类A::BF可以成为A::C朋友,无需前向声明 下面的代码演示了这一点,并用GCC 4.5,VC ++ 10和至less另外一个编译器编译。 class G { friend class F; int g; }; // without this forward declaration, F can't be friend to A::C class F; namespace A { class C { friend class ::F; friend class BF; int c; }; class BF { public: BF() { […]

PHP如何从另一个名字空间导入所有的类

我在我现有的项目中实现名称空间。 我发现你可以使用关键字'use'将类导入到你的名字空间中。 我的问题是,我也可以从1个命名空间导入所有类到另一个。 例: namespace foo { class bar { public static $a = 'foobar'; } } namespace { use \foo; //This doesn't work! echo bar::$a; } 更新PHP 7+ PHP 7中的一个新function是分组声明。 这并不像为给定名称空间中的所有类使用1'use语句'一样简单,但使它更容易一些… 示例代码: <?php // Pre PHP 7 code use some\namespace\ClassA; use some\namespace\ClassB; use some\namespace\ClassC as C; // PHP 7+ code use some\namespace\{ClassA, ClassB, ClassC […]

C ++:命名空间 – 如何正确使用头文件和源文件?

考虑一对两个源文件:一个接口声明文件( *.h或*.hpp )及其实现文件( *.cpp )。 让*.h文件如下所示: namespace MyNamespace { class MyClass { public: int foo(); }; } 我已经看到了在源文件中使用名称空间的两种不同的做法: *.cpp显示练习#1: #include "MyClass.h" using namespace MyNamespace; int MyClass::foo() { … } *.cpp显示练习2: #include "MyClass.h" namespace MyNamespace { int MyClass::foo() { … } } 我的问题:这两种做法是否有区别,是否被认为比另一种更好?

在Windows Update之后,System.Web.Mvc无法正常工作

在昨天的Windows Update之后,我似乎遇到了构build我的项目的问题。 Related Windows Updates could be: ASP.NET MVC 2.0: KB2993939 ASP.NET MVC 3.0: KB2993937 ASP.NET MVC 4.0: KB2993928 ASP.NET MVC 5.0: KB2992080 ASP.NET MVC 5.1: KB2994397 这些错误似乎都与我检查过的System.Web.Mvc命名空间有关。 它仍然与References下的项目有关。 在Windows Update期间,我的MVC项目可能出了什么问题,应该如何解决? 以下是表示今天pipe理的更新的日志:

Struts2没有为命名空间和与上下文path相关联的操作名称

我是Struts2的初学者,我知道这个问题在这里被问了很多次,但我试图解决这个问题,并在这里读了很multithreading,花了6个小时,仍然无法工作。 真的需要更多的build议… 这是我的包 Struts2Test +Struts2Test/src +tw.com.rrstudio.java.test -TestAction.java +Struts2Test/build +Struts2Test/WebContent +Struts2Test/WebContent/META-INF +Struts2Test/WebContent/WEB-INF/classes +Struts2Test/WebContent/WEB-INF/lib -Struts2Test/WebContent/WEB-INF/spring-context.xml -Struts2Test/WebContent/WEB-INF/spring-mvc.xml -Struts2Test/WebContent/WEB-INF/struts.xml -Struts2Test/WebContent/WEB-INF/struts2-action.xml -Struts2Test/WebContent/WEB-INF/web.xml -Struts2Test/WebContent/error.jsp -Struts2Test/WebContent/index.jsp -Struts2Test/WebContent/TestAction.jsp 我的web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>Struts2Test</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring-context.xml /WEB-INF/spring-mvc.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <init-param> <param-name>actionPackages</param-name> <param-value>tw.com.rrstudio.java.test</param-value> </init-param> </filter> <jsp-config> <taglib> <taglib-uri>HTTP://java.sun.com/jsp/jstl/core</taglib-uri> […]

命名空间+函数与类的静态方法

比方说,我有或将要写一组相关的function。 假设他们是math相关的。 在组织上,我应该: 写这些函数,把它们放在我的MyMath命名空间,并通过MyMath::XYZ()引用它们 创build一个名为MyMath的类,并使这些方法是静态的,并引用类似的MyMath::XYZ() 为什么我会select一个作为组织软件的手段?

在c ++头文件中使用“命名空间”

在我们所有的c ++课程中,所有的老师总是using namespace std; #include在.h文件中的#include之后。 这似乎是危险的,因为通过在另一个程序中包含这个头文件,我会得到名字空间导入到我的程序,也许没有意识到,打算或想要(头包含可以非常深的嵌套)。 所以我的问题是双:我是正确的, using namespace不应该在头文件中使用,和/或有一些方法来撤消它,如: //header.h using namespace std { . . . } 还有一个问题应该是这样的:一个头文件应包含所有与.cpp文件相对应的所有头文件,只有那些头文件定义需要的头文件,并且让.cpp文件包含其余的,或者不包含所有头文件它需要作为extern ? 这个问题背后的原因与上面相同:包含.h文件时,我不希望出现意外。 另外,如果我是对的,这是一个常见的错误? 我的意思是在现实世界的编程和在那里的“真实”的项目。 谢谢。

我如何在JavaScript中声明一个名称空间?

如何在JavaScript中创build一个名称空间,以便我的对象和函数不被其他同名对象和函数覆盖? 我用了以下内容: if (Foo == null || typeof(Foo) != "object") { var Foo = new Object();} 有没有更优雅或简洁的方式呢?

如果__name__ ==“__main__”:做什么?

if __name__ == "__main__":做什么? # Threading example import time, thread def myfunction(string, sleeptime, lock, *args): while 1: lock.acquire() time.sleep(sleeptime) lock.release() time.sleep(sleeptime) if __name__ == "__main__": lock = thread.allocate_lock() thread.start_new_thread(myfunction, ("Thread #: 1", 2, lock)) thread.start_new_thread(myfunction, ("Thread #: 2", 2, lock))