complex in header file?

C

chuan

#ifndef _GLUEBALL_H
#define _GLUEBALL_H

#include <complex>

static const complex<int> gamma5[16] =
{ 0,0,1,0, 0,0,0,1, 1,0,0,0, 0,1,0,0 };

#endif


I have error during compiling:
error: expected constructor, destructor, or type conversions before
`<' token


why????
 
J

joshuamaurice

#ifndef _GLUEBALL_H
#define _GLUEBALL_H

#include <complex>

static const complex<int> gamma5[16] =
  { 0,0,1,0, 0,0,0,1, 1,0,0,0, 0,1,0,0 };

#endif

I have error during compiling:
error: expected constructor, destructor, or type conversions before
`<' token

Bad error message from the compiler.
http://www.comeaucomputing.com/tryitout/
gives a much better one.

You want std::complex. complex is a name in a namespace, so you need
to do one of the following:
using namespace std;
using std::complex;
std::complex

Also, don't use names starting with underscores. All global names
starting with underscores are reserved for the implementation (as are
some other names in other scopes), so it's considered bad practice to
ever use a name starting with an underscore, and in your case produces
undefined behavior (?).
 
R

Richard Herring

In message
#ifndef _GLUEBALL_H
#define _GLUEBALL_H

#include <complex>

static const complex<int> gamma5[16] =
  { 0,0,1,0, 0,0,0,1, 1,0,0,0, 0,1,0,0 };

#endif

I have error during compiling:
error: expected constructor, destructor, or type conversions before
`<' token

Bad error message from the compiler.
http://www.comeaucomputing.com/tryitout/
gives a much better one.

You want std::complex. complex is a name in a namespace, so you need
to do one of the following:
using namespace std;
using std::complex;
std::complex

Also, don't use names starting with underscores. All global names
starting with underscores are reserved for the implementation (as are
some other names in other scopes), so it's considered bad practice to
ever use a name starting with an underscore, and in your case produces
undefined behavior (?).

And what on earth are the semantics of std::complex<int> going to be?
std::complex is only intended to be instantiated on floating-point
types, or its behaviour will be so different from that of ordinary
complex numbers that you should be calling it something else.

26.2/2:

The effect of instantiating the template complex for any type other than
float, double or long double is unspecified.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,160
Messages
2,570,889
Members
47,423
Latest member
henerygril

Latest Threads

Top