【发布时间】:2015-06-27 02:54:45
【问题描述】:
我在尝试编译我的程序时遇到了麻烦。问题是我有一个“类的重新定义”。
.cpp 代码
#include "atmosfericConditions.h"
#include <iostream>
using namespace std;
class clsPressure{ //Redefinition of "clsPressure"
float pressure;
public:
clsPressure(){}
clsPressure(float presion){
pressure = presion;
}
friend istream& operator >>(istream &i, clsPressure &e);
friend ostream& operator <<(ostream &o, const clsPressure &s);
};
istream& operator >>(istream &i, clsPressure &e){
char sign;
i >> e.pressure >> sign >> sign;
return i;
}
ostream& operator <<(ostream &o, const clsPressure &s){
o << s.pressure << " Pa";
return o;
}
class clsDensity{ //Redefinition of "clsDensity"
float density;
public:
clsDensity(){}
clsDensity(float densdad){
density = densdad;
}
friend istream& operator >>(istream &i, clsDensity &e);
friend ostream& operator <<(ostream &o, const clsDensity &s);
};
istream& operator >>(istream &i, clsDensity &e){
char sign;
i >> e.density >> sign >> sign >> sign >> sign >> sign >> sign;
return i;
}
ostream& operator <<(ostream &o, const clsDensity &s){
o << s.density << " Kg/m^3";
return o;
}
class clsSoundVelocity{ //Redefinition of "clsSoundVelocity"
float soundVelocity;
public:
clsSoundVelocity(){}
clsSoundVelocity(float velocidadDelSonido){
soundVelocity = velocidadDelSonido;
}
friend istream& operator >>(istream &i, clsSoundVelocity &e);
friend ostream& operator <<(ostream &o, const clsSoundVelocity &s);
};
istream& operator >>(istream &i, clsSoundVelocity &e){
char sign;
i >> e.soundVelocity >> sign >> sign >> sign;
return i;
}
ostream& operator <<(ostream &o, const clsSoundVelocity &s){
o << s.soundVelocity << " m/s";
return o;
}
class clsDynamicViscocity{ //Redefinition of "clsDynamicViscocity"
double dynamicViscocity;
public:
clsDynamicViscocity(){}
clsDynamicViscocity(double viscocidadDinamica){
dynamicViscocity = viscocidadDinamica;
}
friend istream& operator >>(istream &i, clsDynamicViscocity &e);
friend ostream& operator <<(ostream &o, const clsDynamicViscocity &s);
};
istream& operator >>(istream &i, clsDynamicViscocity &e){
char sign;
i >> e.dynamicViscocity >> sign >> sign >> sign >> sign >> sign;
return i;
}
ostream& operator <<(ostream &o, const clsDynamicViscocity &s){
o << s.dynamicViscocity << " N/m^2";
return o;
}
前一个.cpp的.h代码
//
// atmosfericConditions.h
// IASS Project
//
// Created by Oscar Espinosa on 6/26/15.
// Copyright (c) 2015 IPN ESIME Ticoman. All rights reserved.
//
#ifndef atmosfericConditions_h
#define ATMOSFERICCONDITIONS_H_
#include <iostream>
using namespace std;
class clsPressure{
float pressure;
public:
clsPressure(){}
clsPressure(float presion){
pressure = presion;
}
friend istream& operator >>(istream &i, clsPressure &e);
friend ostream& operator <<(ostream &o, const clsPressure &s);
};
class clsDensity{
float density;
public:
clsDensity(){}
clsDensity(float densdad){
density = densdad;
}
friend istream& operator >>(istream &i, clsDensity &e);
friend ostream& operator <<(ostream &o, const clsDensity &s);
};
class clsSoundVelocity{
float soundVelocity;
public:
clsSoundVelocity(){}
clsSoundVelocity(float velocidadDelSonido){
soundVelocity = velocidadDelSonido;
}
friend istream& operator >>(istream &i, clsSoundVelocity &e);
friend ostream& operator <<(ostream &o, const clsSoundVelocity &s);
};
class clsDynamicViscocity{
double dynamicViscocity;
public:
clsDynamicViscocity(){}
clsDynamicViscocity(double viscocidadDinamica){
dynamicViscocity = viscocidadDinamica;
}
friend istream& operator >>(istream &i, clsDynamicViscocity &e);
friend ostream& operator <<(ostream &o, const clsDynamicViscocity &s);
};
#endif
我注意到,它在 .cpp 和 .h 中的代码相同。我一直在寻找视频中的一些答案,但我找不到任何可以帮助我的东西。我尝试删除 .cpp 并仅保留 .h,但它不起作用。
如您所见,Xcode 通知我问题出在 .cpp 的类中。
【问题讨论】:
标签: c++ xcode redefinition