我是一个新手,C++和我写一个程序添加两个复数:错误:“的Imag”没有指定类型
这里是我的.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){
^
有人可以帮我吗?非常感谢!
您需要在类声明结尾处使用';'。 – Jamal
一旦你解决了这个问题,阅读关于物体和指针之间的区别,并摆脱那个邪恶的'新''。 –
它会编译吗?将新的结果分配给对象的含义是什么? :\ – ApplePie