gpt4 book ai didi

c++ - 错误 C2062 : type int unexpected

转载 作者:行者123 更新时间:2023-11-30 04:23:24 28 4
gpt4 key购买 nike

我是 c++ 和 SWIG 的新手

我正在 Windows 环境中使用 SWIG 创建一个 python 模块。

创建包装器类 (example_wrap.cxx) 之后。开始使用 (python setup.py build_ext --inplace) 构建 python 模块。

但我收到了*example_wrap.cxx(3090) : error C2062: type 'int' unexpected*

GradedComplex.h:

class GradedComplex
{
public:
typedef std::complex<double> dcomplex;
typedef Item<dcomplex> item_type;
typedef ItemComparator<dcomplex> comparator;
typedef std::set<item_type, comparator> grade_type;

private:
int n_;
std::vector<grade_type *> grade_;
std::vector<double> thre_;

public:
GradedComplex(int n, double *thre);
~GradedComplex();

void push(item_type item);
void avg(double *buf);
};

#endif

GradedComplex.cc

GradedComplex::GradedComplex(int n, double *thre)
{
n_ = n;
for (int i = 0; i < n_; ++i)
{
thre_.push_back(thre[i]);
grade_.push_back(new grade_type());
}
}

然后我构建它以使用 SWIG 生成 python 模块。

Swig接口(interface)文件(example.i) GradedComplex(int n, double *thre);

我对 SWIG 接口(interface)文件不是很了解

生成的包装类代码量很大,所以我只粘贴了一些。

代码:example_wrap.cxx

3083: #define SWIG_FILE_WITH_INIT
3084: #include "Item.h"
3085: #include "GradedComplex.h"
3086: typedef std::complex<double> dcomplex;
3087: typedef Item<dcomplex> item_type;
3088: typedef ItemComparator<dcomplex> comparator;
3089: typedef std::set<item_type, comparator> grade_type;
3090: GradedComplex(int n, double *thre);
3091: void push(item_type item);
3092: void avg(double *buf);
3093: #include <string>
3094: #include <complex>
3095: #include <iostream>
3096: #if PY_VERSION_HEX >= 0x03020000
3097: # define SWIGPY_SLICE_ARG(obj) ((PyObject*) (obj))
3098: #else
3099: # define SWIGPY_SLICE_ARG(obj) ((PySliceObject*) (obj))
3100: #endif

GradedComplex 构造函数:

GradedComplex::GradedComplex(int n, double *thre)
{
n_ = n;
for (int i = 0; i < n_; ++i)
{
thre_.push_back(thre[i]);
grade_.push_back(new grade_type());
}
}

请建议纠正此错误

最佳答案

您显然在某个头文件(GradedComplex.h?)的某处声明了类 GradedComplex

稍后您尝试在此行中使用此名称

GradedComplex(int n, double *thre);

对于人类读者来说,这一行可能看起来像是在尝试声明一个独立函数 GradedComplex。从技术上讲,拥有与现有类同名的函数是合法的。但是,由于您没有为此函数指定返回类型,因此编译器不会将其视为函数声明。编译器认为您正在尝试声明类型为 GradedComplex 的对象,声明符周围有多余的括号,如

GradedComplex (a);

由于这个原因,int 的出现使它感到困惑,并导致在第 3090 行报告有关意外 int 的错误报告。

你想做什么?如果您尝试为 GradedComplex 定义一个构造函数,那么您已经知道该怎么做(您自己发布了一个正确的定义)。 3090行的目的是什么?为什么要写那一行?

关于c++ - 错误 C2062 : type int unexpected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13384935/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com