Wednesday, 13 May 2015

Class redefinition error


hi everyone,

first of i'm pretty sure i'm not first 1 error every similar thread found either didn't me answer or wasn't relevant enough.
so, why not try creating own thread?

in obscure financial engineering class, have use different math transforms (some using fft).
in order make work had create 2 classes: complex , options.

first time ran code, in order test methods within classes, worked fine. now, everytime build, semantic issue - redefinition of 'complex' // 'options'.
xcode points out fact included header files in other .cpp // .h files , tell me previous definitions there.
don't should do!

btw, i'm under snow leopard , using xcode 4.0.1

below header 1 of classes, , i'm #includ-ing in several other files.

thanks!

code:
  class complex {  public:      complex(float realpart=0, float imaginarypart=0);      complex add(const complex &c) const;      float getreal() const;      float getimaginary() const;      void setreal(float r);      void setimaginary(float i);      void fft(double* x);      complex multiply(const complex &a) const;      complex power(float p) const;      float norm() const;      complex coshc() const;      complex sinhc() const;      complex cothc() const;      float arg() const;      complex expcomplex() const;      void outprint() const;  private:      float real;      float imaginary;  };  
 

you're including multiple times, why you're getting error.

it's idea wrap include files #ifndef based on name of include file. file you'd put lines:
#ifndef _complex_h
#define _complex_h 1
//your file here
#endif

around file. keep being included more once.
 


Forums Macs Mac Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

No comments:

Post a Comment