小编dyo*_*mas的帖子

嵌套模板类,指针指向方法未在clang ++中编译

我的问题的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的实验没有结果.

c++ gcc templates clang++

23
推荐指数
1
解决办法
763
查看次数

Python在加载C++编写的扩展模块时接收SIGSEGV

正确的代码示例:

#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)个故意错误:

  • 变量some​​Constant声明但从未定义;

  • 函数some_function定义,但从未调用过;

如果由dlopen/dlsym编译和打开:

sf.so: undefined symbol: someConstant
Run Code Online (Sandbox Code Playgroud)

按要求.但如果由Python解释器加载:

>>> …
Run Code Online (Sandbox Code Playgroud)

c++ python unix

6
推荐指数
1
解决办法
422
查看次数

对于具有受限存储的枚举,类型转换在switch中失败

SSCCE:

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 storageofftopic

c++ g++ switch-statement bit-fields enum-class

5
推荐指数
1
解决办法
120
查看次数

标签 统计

c++ ×3

bit-fields ×1

clang++ ×1

enum-class ×1

g++ ×1

gcc ×1

python ×1

switch-statement ×1

templates ×1

unix ×1