svs
svs

Reputation: 251

error C2062 : type int unexpected

I am new to c++ and SWIG

I am creating a python module using SWIG in windows environment.

After creating wrapper class (example_wrap.cxx). Started building using (python setup.py build_ext --inplace) for creating python module.

But I am getting *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());
  }
}

Then I build it for generating python module using SWIG.

Swig interface file (example.i) GradedComplex(int n, double *thre);

I am not much expert in SWIG interface file

The wrapper class generated has large volume of code so i am pasting few.

code : 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

The GradedComplex constructor:

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());
  }
}

Please suggest a to rectify this error

Upvotes: 1

Views: 13953

Answers (2)

AnT stands with Russia
AnT stands with Russia

Reputation: 320361

You apparently declared class GradedComplex somewhere in some header file (GradedComplex.h?)

Later you attempted to use this name in this line

GradedComplex(int n, double *thre);

To a human reader this line would probably look like an attempt to declare an independent function GradedComplex. Technically, it is legal to have a function with the same name as an existing class. However, since you specified no return type for this function, the compiler does not see this as a function declaration. The compiler thinks you are trying to declare an object of type GradedComplex with redundant parentheses around the declarator, as in

GradedComplex (a);

For this reason, the appearance of that int confuses it and leads to an error report about an unexpected int in line 3090.

What were you trying to do? If you were trying to define a constructor for GradedComplex, then you already know how to do it (you posted a correct definition yourself). What is the purpose of line 3090? Why did you write that line?

Upvotes: 1

Ivaylo Strandjev
Ivaylo Strandjev

Reputation: 70931

You can not have a function with no return type in c++. You should set a return type for the function GradedComplex. Constructors can not be declared like that.

Upvotes: 1

Related Questions