【问题标题】:c++ Error 3 error C2159: more than one storage class specifiedc++ Error 3 error C2159: more than one storage class specified
【发布时间】:2014-11-29 18:38:30
【问题描述】:

我使用 Visual Studio 2008 编译我的源代码,但它一直给我这个错误:

c++ Error   3   error C2159: more than one storage class specified

我为此度过了一个不眠之夜,却不知道问题出在哪里。

C++ 代码

    #pragma once

#define SET_EXCEPTION(x) PyErr_SetString(PyExc_RuntimeError, #x)

bool PyTuple_GetString(PyObject* poArgs, int pos, char** ret);
bool PyTuple_GetInteger(PyObject* poArgs, int pos, unsigned char* ret);
bool PyTuple_GetInteger(PyObject* poArgs, int pos, int* ret);
bool PyTuple_GetInteger(PyObject* poArgs, int pos, WORD* ret);
bool PyTuple_GetByte(PyObject* poArgs, int pos, unsigned char* ret);
bool PyTuple_GetUnsignedInteger(PyObject* poArgs, int pos, unsigned int* ret);
bool PyTuple_GetLong(PyObject* poArgs, int pos, long* ret);
bool PyTuple_GetUnsignedLong(PyObject* poArgs, int pos, unsigned long* ret);
bool PyTuple_GetFloat(PyObject* poArgs, int pos, float* ret);
bool PyTuple_GetDouble(PyObject* poArgs, int pos, double* ret);
bool PyTuple_GetObject(PyObject* poArgs, int pos, PyObject** ret);
bool PyTuple_GetBoolean(PyObject* poArgs, int pos, bool* ret);

bool PyCallClassMemberFunc(PyObject* poClass, const char* c_szFunc, PyObject* poArgs);
bool PyCallClassMemberFunc(PyObject* poClass, const char* c_szFunc, PyObject* poArgs, bool* pisRet);
bool PyCallClassMemberFunc(PyObject* poClass, const char* c_szFunc, PyObject* poArgs, long * plRetValue);

bool PyCallClassMemberFunc_ByPyString(PyObject* poClass, PyObject* poFuncName, PyObject* poArgs);
bool PyCallClassMemberFunc(PyObject* poClass, PyObject* poFunc, PyObject* poArgs);

PyObject * Py_BuildException(const char * c_pszErr = NULL, ...);
PyObject * Py_BadArgument();
PyObject * Py_BuildNone();
PyObject * Py_BuildEmptyTuple();

static auto &&PyTuple_GetDWORD = PyTuple_GetUnsignedLong;

编译器指出错误在第31行,即

static auto &&PyTuple_GetDWORD = PyTuple_GetUnsignedLong;

任何帮助将不胜感激!

【问题讨论】:

  • 我认为 Visual Studio 2008 不支持右值引用或 auto。您需要 VS2012 或更高版本才能获得 C++11 功能。
  • 这个源码是和我同行业的其他竞争对手在VS2008上编译的。请考虑查看项目 SLN 中的以下几行:Microsoft Visual Studio 解决方案文件,格式版本 10.00 # Visual Studio 2008
  • 根据这个VS2010有右值和自动支持,但绝对不是2008:msdn.microsoft.com/en-us/library/hh567368.aspx
  • 查看@JonathanPotter 的评论。当我不得不回滚我开始对一些 VS2010 项目所做的更改时,当我被告知它们必须是源 VS2008 兼容的回补丁时,我哭了。我不得不把auto 放回架子上,直到尼安德特人决定是时候走出铁器时代了。
  • 感谢您的帮助,我将升级到 Visual Studio 2010,看看会发生什么。再次感谢您。

标签: c++


【解决方案1】:

关键字auto 在 C++11 之前有不同的含义。这意味着一个变量是一个自动变量,它的范围是本地的。在 C++11 中,其含义变为“推断变量的类型”。

由于 VS 2008 不支持 C++11 结构,它会将 auto 解释为其旧含义。当这样解释时,

static auto &&PyTuple_GetDWORD = PyTuple_GetUnsignedLong;

没有意义,因为变量不能同时是 staticauto

相关帖子:Goal of C's "auto" keyword

【讨论】:

猜你喜欢
  • 2019-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-23
  • 1970-01-01
  • 2022-12-06
  • 2014-08-06
相关资源
最近更新 更多