- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我不知道如何解释为什么创建成员有效 inner
在类模板中 OuterTempl<T>
而在未模板类中这样做是非法的 Outer
.
// Non-template version
struct Outer
{
struct Inner;
Inner inner; // incomplete type (I get this)
};
struct Outer::Inner
{
};
// Template version
template<typename T>
struct OuterTempl
{
struct InnerTempl;
InnerTempl inner; // OK ... Huh!?
};
template<typename T>
struct OuterTempl<T>::InnerTempl
{
};
int main()
{
}
另见 ideone .
最佳答案
是的 - 考虑 [temp.mem.class]/1:
A member class of a class template may be defined outside the class template definition in which it is declared.
[ Note: The member class must be defined before its first use that requires an instantiation (14.7.1). For example,template<class T> struct A {
class B;
};
A<int>::B* b1; // OK: requires A to be defined but not A::B
template<class T> class A<T>::B { };
A<int>::B b2; // OK: requires A::B to be defined— end note ]
同样重要的是要提到inner
的定义,它构成了上面注释描述的Inner
的使用,只有在需要时才会被实例化:
Unless a member […] has been explicitly instantiated or explicitly specialized, the specialization of the member is implicitly instantiated when the specialization is referenced in a context that requires the member definition to exist;
由于您的代码中没有 OuterTempl
的实例化,因此永远不会实例化 inner
的定义,并且永远不会实例化 Inner
必要的。因此,仅在实例化时才需要此类声明的嵌套类类型的完整性。您没有在此处实例化 OuterTempl
,但如果您在 Inner
的定义之前执行此操作,则代码格式不正确。
也就是说,
template<typename T>
struct OuterTempl
{
struct InnerTempl;
InnerTempl inner;
};
template struct OuterTempl<int>; // Bad - Ill-formed (NDR?)
template<typename T>
struct OuterTempl<T>::InnerTempl {};
template struct OuterTempl<int>; // Fine
Demo .
关于c++ - 类模板的嵌套类可以是 "incomplete",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27760896/
import numpy as np from matplotlib import pyplot as plt import scipy.io.wavfile as wav from numpy.li
我正在尝试编译以下内容(在 MSVC 中): #define TRAP (errorCode = (errorCode != 0) ? errorCode :) int someFunction(
下面的代码究竟是如何工作的? #include template T x = T{}; void foo() { class Test { public: T
我不知道如何解释为什么创建成员有效 inner在类模板中 OuterTempl而在未模板类中这样做是非法的 Outer . // Non-template version struct Outer {
我正在查看 tensorflow 日志并发现以下行: 4 ops no flops stats due to incomplete shapes. Consider passing run_meta
我正在尝试使用Visual Studio 2019的内置编译器读取C++中的文件。在发现一些示例之后,我尝试这样做: #include using namespace std; int main()
我是一个相对较新的 C 程序员,所以请容忍我的无知:-)我正在尝试为 valgrind 编译提供一个自定义工具。该工具最初是大约 8 年前编写的,基于更旧版本的 valgrind。原始版本的 valg
我正在 recv while 循环中将一些数据读入缓冲区。 缓冲区前面有内容,我需要查看这些内容并获取剩余的字节。因此,我使用指针在缓冲区中导航以获取所需的字符,以便将剩余字节复制到另一个缓冲区中。
在下面的代码中,我想使用默认构造函数{.data = value},因为我希望我的类是POD。我不明白我在编译时收到的错误消息(llvm 或 gnu,c++11): #include class a
我有一个类应该有同一个类的私有(private)成员,例如: class A { private: A member; } 但它告诉我 member 是不完整的类型。为什么?如
Get-Process s* | where {s$_.Path} | dir | sort LastWriteTime | Format-Table fullname
我正在使用 RStudio,并尝试在我当前的项目中使用 packrat。我单击“在此项目中使用 packrat”复选框并按“确定”,我从控制台获得以下输出: > packrat::init()
我想使用 API 检索所有未删除且不完整的订单的列表。即类似于您可以在 Bigcommerce 管理页面上查看的订单列表。我知道我可以将 is_deleted 标志设置为 false 来过滤这些,但我
这个问题和看到的类似here . 我有大量大型 CSV,我正在通过函数连续加载和解析它们。其中许多 CSV 没有问题,但是当我尝试使用 read.csv() 加载它们时,有几个会导致问题。 我已将其中
我正在尝试将库移植到 Mac OS X。编译器报告了不完整的类型错误。具体来说:字段的类型不完整'header_t []。但是,当我查看源代码时,header_t 是在 packet_state_t
如果我有定义: typedef struct y_t *Y; 和 typedef struct x_t *X; struct x_t { Y *b; Y a; int s
这个问题已经有答案了: C programming decoupling interface from implementation with struct forward declaration (
当我尝试在 java 应用程序中执行密码查询时,遇到了一个奇怪的问题。result.dumpToString()- 方法向我显示了正确的结果。但是当我尝试迭代时,最后一个节点总是丢失(对于每个执行的查
我不确定为什么会收到此错误...“错误:字段‘config’的类型不完整”。我尝试做前向声明并使用#include 包含 header ...我只是想在 fInstance 中包含 fConfig..
我尝试的一切都给我 Incomplete(Size(1))。我现在最好的猜测是: named!(my_u64(&str) -> u64, map_res!(recognize!(nom::di
我是一名优秀的程序员,十分优秀!