我知道C#支持命名空间嵌套,C++也支持,两者都允许这样的代码.
namespace A {
namespace B {
...
}
}
来自C++背景,深入到C#世界中,我一直在思考如何通过所有必须发出的使用.NET的指令对组件进行分层嵌套,例如
using System.Collections;
using System.Collections.Generic;
我确信微软打算并设计这些库是按逻辑层次组织的,但如果没有查看源代码,我无法验证System.Collections.Generic是否具有嵌套的集合命名空间,但我假设是这样的,而且它是用A和B所见的
考虑下面的程序。它是否符合c++标准(需要参考标准的相关部分):
namespace X { extern int i; }
namespace N { using X::i; }
int N::i = 1;
int main() {}
我对不同的编译器得到了不同的结果。我正在尝试弄清楚我应该为哪个编译器提交错误报告:
Clang:给出以下编译器错误:命名空间‘N’中没有名为'i‘的成员GCC和Visual C++编译它时没有错误。
为了进行比较,下面给出了所有三个编译器的编译器错误:
namespace X { void f(); }
namespace N { using
摘要:
是否有任何文档(如c++标准)支持使用以下样式定义C++类的有效性:
namespace N { class X; }
class N::X { ... }
详细信息:
我们在我们公司的代码中使用了几种样式来定义类:
// n_x.h - style 1
namespace N {
class X;
}
class N::X {...}
和
// n_y.h - style 2
namespace N {
class Y;
}
namespace N {
class Y { ... };
}
这里的主要区别是样式1中的class N::X和样式2中的namespace
我正在尝试在c++中制作一个托管c++,它需要对多线程的支持。我正在visual 2013中开发,使用平台工具集版本v120。我之所以需要这个托管程序集,是因为它需要在LabView中集成程序集。
遵循中的步骤,取得了良好的效果。但是,我显然需要实现一些更复杂的东西,当我包括线程和编写以下代码时:
#pragma once
#include <thread>
using namespace System;
using namespace std;
namespace MultiThread_module {
public ref class multiThreadi
我主要指的是C++03标准,但看了一眼之后,它也应该适用于C++11标准。
以下代码在VC++2010中成功编译和执行:
template<typename T>
class CC {
public:
T f(T a) {
return a*a;
}
};
template<>
class ::CC<int> { //<--- ::CC<int> syntax allowed by VC++2010, but is it non-standard ?
public:
i
在没有任何类、模板、枚举或类型定义的转换单元中给定嵌套名称说明符A::,如果格式正确,标识符A必须引用名称空间。
例如:
namespace X
{
int i;
}
int main()
{
X::i = 42; // Here X:: is a nested-name-specifier
// and X is a namespace-name
// i is looked up qualified w.r.t. X
}
在上面的例子中,A是X,但是我的问题是关于一般情况。
在A::中如何对命名空间名称A进行名称
我有一个关于C++前向声明的问题
class Outer::Inner; // not valid. error
class Outer {
Inner * inn; // not valid, needs forward declaration.
class Inner {
}
}
但是,当像这样实施时:
// class Outer::Inner; // not valid. error
class Outer {
class Inner; // forward-"like" declaration within class
Inne
下面的代码有效吗?
struct A
{
struct nested;
};
struct B : public A {};
struct B::nested {};
gcc接受了它,但是clang拒绝了它,并犯了以下错误:
test.cpp:8:14: error: no struct named 'nested' in 'B'
class B::nested {};
~~~^
如果您使用名称空间来分隔模块/结构化,则头文件中的嵌套和缩进会显着增加。有没有办法以更短的方式编写下面的代码?
namespace A
{
namespace B
{
namespace C
{
namespace D
{
namespace E
{
template <typename T>
public class X
我正在做一个简单的游戏,有统计(力量,智慧,魅力.)和技能(采矿,游泳,骑马.)。这些结构组织在类Types中。
我想在所有文件中找到那些结构。在C++中,我可以只包含类并使用struct,但在C#中不能这样做。
有办法让这件事成功吗?
这是我的简化代码
public class Types{
public struct stats{
float str;
float con;
float inte;
}
public struct skill{
float mining;
}
}
public
我不知道该怎么定义我的问题。假设下面的代码将每个区域命名为A、B、C,有些类型是可声明的,有些是不可能的。我想知道这个区别。
(代码只是一个愉快的例子。)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// Area A
delegate int MyDelegate(int a, int b);
public enum myenum { a,b,c };
class another { }
//int a;
是否可以向前声明一个嵌套类,然后将其用作外部类的具体(而不是指向/引用)数据成员的类型?
也就是说。
class Outer;
class Outer::MaybeThisWay // Error: Outer is undefined
{
};
class Outer
{
MaybeThisWay x;
class MaybeThatOtherWay;
MaybeThatOtherWay y; // Error: MaybeThatOtherWay is undefined
};
我正在从java背景中学习c++。我想知道如何在命名空间中创建私有函数?
我想用cpp来做这件事
Java:
public class Clazz {
public static void foo() {
// stuff
}
private static void bar() {
// other stuff
}
}
C++:
namespace clazz {
void foo();
// what do I do here?
}
我正在寻找一种官方的(或至少半官方的)方式来暴露我的操作员在我的标准类库。
例如,我实现了一个,这样就可以在编译时编写128个位整数。到目前为止,当我实现运算符时,我只会将它们放在我的命名空间之外,以使它们都在没有using namespace snapdev的情况下工作--这很糟糕,因为这会带来名称空间中的所有内容,我当然不想这样做。
对于文字,我已经看到您可以使用namespace literals子名称空间,就像在中一样。
现在,我有许多类,它们有一个与我的ostream实现类似的相应的运算符:
template<class E, class S, class T, class S
我对C#中名称空间的结构有点困惑,我是C#和WPF的新手
当我创建WPF的新项目时,默认情况下,这些命名空间包含在顶部。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.
我不确定B类中的两个数据成员声明是否等效。
//file0.h
namespace C
{
typedef int Id;
}
//file1.h
namespace A
{
typedef int Id;
}
//file2.h
namespace A
{
class B
{
public:
// ...
//Want to add data member theId as:
//Id theId;
//or
//A::Id theId;
}
}
也就是说,在没有A::的情况下,C++标准