我的问题的SSCCE是:
template <class T> class MyClass
{
template <void (MyClass::*M)() const> struct wrapper
{
virtual void call();
};
};
template <typename T>
template <void (MyClass<T>::*M)() const>
void MyClass<T>::wrapper<M>::call()
{
}
Run Code Online (Sandbox Code Playgroud)
此代码在gcc中编译但失败并出现错误:
error: nested name specifier 'MyClass<T>::wrapper<M>::' for declaration does not refer into a class, class template or class template partial specialization
void MyClass<T>::wrapper<M>::call()
~~~~~~~~~~~~~~~~~~~~~~~~~^
Run Code Online (Sandbox Code Playgroud)
在clang ++中.为什么?
在课堂上,电话定义解决了这个问题,我知道.任何非指针方法模板都可以在任何地方正常工作.使用template/typename的实验没有结果.
正确的代码示例:
#include "Python.h"
#include <string>
extern const int someConstant;
void some_function()
{
const char *begin = NULL;
const char *end = NULL;
std::string s(begin, end);
const int v = someConstant;
}
static PyMethodDef _G_methods[] =
{
{NULL, NULL, 0, NULL} /* Sentinel */
};
PyMODINIT_FUNC initsf()
{
PyObject *module;
if (!(module = Py_InitModule("sf", _G_methods)))
{
return;
}
PyObject *pyerror = PyErr_NewException("fs.error", NULL, NULL);
Py_INCREF(pyerror);
PyModule_AddObject(module, "error", pyerror);
}
Run Code Online (Sandbox Code Playgroud)
这是扩展模块草案.尽可能简单.它有一个空的方法表和从原始docpage复制的初始化函数.它包含2(2)个故意错误:
变量someConstant声明但从未定义;
函数some_function定义,但从未调用过;
如果由dlopen/dlsym编译和打开:
sf.so: undefined symbol: someConstant
Run Code Online (Sandbox Code Playgroud)
按要求.但如果由Python解释器加载:
>>> …Run Code Online (Sandbox Code Playgroud) enum class confirm {yes};
struct item
{
confirm s:4; // (1) limiting storage size required
};
int main()
{
item itm;
itm.s = confirm::yes; // (2) OK
switch (itm.s)
{
case confirm::yes: // (3) Failure, need static data cast here?
break;
}
}
Run Code Online (Sandbox Code Playgroud)
产生错误:
In function ‘int main()’:
error: could not convert ‘yes’ from ‘confirm’ to ‘int’
case confirm::yes:
^
Run Code Online (Sandbox Code Playgroud)
用g ++编译但用clang ++编译好.为什么分配标记为(2)可能但是由(3)标记的案例条款不是?
警告约too small storage是offtopic