-1

私は C++ の初心者で、2 つの複素数を加算するプログラムを作成しています。

ここに私の.hファイルがあります:

#ifndef IMAGINE_H
#define IMAGINE_H

#include<iostream>
using std::ostream;

class Imag{
public:
  double real;
  double imag;

  Imag() = default;
  Imag(double,double);

  Imag add(Imag);
};

#endif

ここに私の.cppファイルがあります:

#include<iostream>
#include"imagine.h"
using namespace std;

Imag::Imag(){
  this-> real;
  this-> imag;

}
Imag  Imag:: add(Imag i){
  Imag result = new Image();
  result -> real = this->real + i -> real;
  result -> imag = this-> imag + i-> imag;
  return result;
}

コンパイルすると、次のように文句を言います。

imagine.cpp:5:1: error: ‘Imag’ does not name a type
 Imag::Imag(){
 ^
imagine.cpp:10:1: error: ‘Imag’ does not name a type
 Imag  Imag:: add(Imag i){
 ^

誰でもこれで私を助けることができますか? 本当にありがとう!

4

2 に答える 2

4

クラス宣言がセミコロンで終わっていません。これは適切な構文です。

class ClassName { /* */ };

于 2013-09-22T19:54:37.740 に答える