私は 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){
^
誰でもこれで私を助けることができますか? 本当にありがとう!