난 그냥이 무시 무시한 멍청한 실수 인 경우 프로그래밍이 너무 실례 C++를 시작했습니다,하지만 내 머리를하고있어. 내가 여러 .CPP이수백 "라는 이름의 회원이 없습니다 ..."오류 C++
파일을 올바르게 프로그램하고 컴파일 한 후에는 오류없이 모든 파일을 자체 .h 파일로 만듭니다.
어떤 이유, 나는 모두의 라인을 따라, "flyingUnit.cpp"나는 오류의 수백을 얻을라는 하나 개의 클래스를 컴파일 할 때 :
flyingUnit.cpp: In constructor ‘FlyingUnit::FlyingUnit(const char*, const char*, double, double,
bool, const char*, const char*, int, const char*)’:
flyingUnit.cpp:26:38: error: class ‘FlyingUnit’ does not have any field named ‘length’
const char* weyr) : length(length), wingspan(wingspan), age(age)
^
나는이 이유에 관해서는 전혀 생각이 없다 일어나는 모든 클래스에서 사용되는 모든 발견되지 않습니다, 완전히 다른 모든 클래스와 완벽하게 정상적으로 작동하는 것처럼 보였을 때 완전히 어이가 없어졌습니다. 이러한 오류가 발생하는 이유는 무엇입니까?
flyingUnit.h :
#ifndef FLYING_UNIT_H
#define FLYING_UNIT_H
#include "rider.h"
#include "dragon.h"
#include "fall.h"
const int MAX_FALLS = 20;
class FlyingUnit
{
public:
FlyingUnit() = default;
FlyingUnit(const char* dragonName, const char* dragonColour,
double length, double wingspan, bool breatheFire,
const char* riderName, const char* rank, int age,
const char* weyr);
void addFlyingUnit(const char* dragonName, const char* dragonColour,
double length, double wingspan, bool breatheFire,
const char* riderName, const char* rank, int age,
const char* weyr);
void setRank(const char* rank);
void setWeyr(const char* weyr);
int getFallCount() const { return fallCount; }
void addFall(const char* location, int day, int month, int year);
friend ostream& operator << (ostream& os, const FlyingUnit& f);
friend istream& operator >> (istream& is, FlyingUnit & f);
friend ofstream& operator << (ofstream& os, const FlyingUnit& f);
friend ifstream& operator >> (ifstream& is, FlyingUnit& f);
const char* getRiderName() const;
const char* getDragonName() const;
private:
Rider rider;
Dragon dragon;
Fall falls[ MAX_FALLS ];
int fallCount = 0;
};
#endif
flyingUnit.cpp :
#include "flyingUnit.h"
#include <iostream>
#include <cctype>
#include <string.h>
int main()
{
return 0;
}
FlyingUnit::FlyingUnit(const char* dragonName, const char* dragonColour,
double length, double wingspan, bool breatheFire,
const char* riderName, const char* rank, int age,
const char* weyr) : length(length), wingspan(wingspan), age(age)
{
strcpy(this->dragonName, dragonName);
strcpy(this->dragonColour, dragonColour);
this->breatheFire = breatheFire;
strcpy(this->riderName, riderName);
strcpy(this->rank, rank);
strcpy(this->weyr, weyr);
}
ostream& operator << (ostream& os, const FlyingUnit& f)
{
os << "Dragon Name: " << f.dragonName
<< "Dragon Colour: " << f.dragonColour
<< "Length: " << f.length
<< "Wingspan: " << f.wingspan
<< "Breathes Fire: " << f.breatheFire
<< "Rider Name: " << f.riderName
<< "Rank: " << f.rank
<< "Age: " << f.age
<< "Weyr: " << f.weyr << endl;
return os;
}
istream& operator >> (istream& is, FlyingUnit & f)
{
char temp[500];
cout << "Enter Dragon Name: ";
is.getline(temp, 500);
strcpy(f.dragonName, temp);
cout << "Enter Dragon Colour: ";
is.getline(temp, 500);
strcpy(f.dragonColour);
cout << "Length: ";
is >> f.length;
is.ignore(100000, "\n");
cout << "Wingspan: ";
is >> f.wingspan;
is.ignore(100000, "\n");
//cout << "Breathes Fire: ";
// is.getline(temp, 500);
cout << "Enter Rider Name: ";
is.getline(temp, 500);
strcpy(f.riderName, temp);
cout << "Rank: ";
is >> f.rank;
is.ignore(100000, "\n");
cout << "Age: ";
is >> f.age;
is.ignore(100000, "\n");
cout << "Weyr: ";
is.getline(temp, 500);
strcpy(f.weyr, temp);
return is;
}
ofstream& operator << (ofstream& os, const FlyingUnit& f)
{
os << f.dragonName << endl
<< f.dragonColour << endl
<< f.length << endl
<< f.wingspan << endl
<< f.breatheFire << endl
<< f.riderName << endl
<< f.rank << endl
<< f.age << endl
<< f.weyr << endl;
return os;
}
ifstream& operator >> (ifstream& is, FlyingUnit& f)
{
char temp[500];
is.getline(temp, 500);
strcpy(f.dragonName, temp);
is.getline(temp, 500);
strcpy(f.dragonColour);
is >> f.length;
is.ignore(100000, "\n");
is >> f.wingspan;
is.ignore(100000, "\n");
//cout << "Breathes Fire: ";
// is.getline(temp, 500);
is.getline(temp, 500);
strcpy(f.riderName, temp);
is >> f.rank;
is.ignore(100000, "\n");
is >> f.age;
is.ignore(100000, "\n");
is.getline(temp, 500);
strcpy(f.weyr, temp);
return is;
}
편집
내가 만든했는데 잘 작동 다른 클래스와 .H 파일을 제공합니다:
를Rider.cpp
#include "rider.h"
int main()
{
return 0;
}
Rider::Rider(const char* name, int age, const char* rank,
const char* weyr) : age(age)
{
this->name = new char[ strlen(name) + 1 ];
strcpy(this->name, name);
this->rank = new char[ strlen(rank) + 1 ];
strcpy(this->rank, rank);
this->weyr = new char[ strlen(weyr) + 1 ];
strcpy(this->weyr, weyr);
}
ostream& operator << (ostream& os, const Rider& r)
{
os << "Rider name: " << r.name
<< " Age: " << r.age
<< " Rank: " << r.rank
<< " Weyr: " << r.weyr << endl;
return os;
}
istream& operator >> (istream& is, Rider& r)
{
char temp[ 500 ];
cout << "Enter Rider name >> ";
is.getline(temp, 500);
r.name = new char[strlen(temp) + 1 ];
strcpy(r.name, temp);
cout << "Enter Rider age >> ";
is >> r.age;
// clean up the newline left after the int read
// as we are going to read text next.
is.ignore(100000, '\n');
cout << "Enter Rider rank >> " ;
is.getline(temp, 500);
r.rank = new char[ strlen(temp) + 1];
strcpy(r.rank, temp);
cout << "Enter Rider weyr >> " ;
is.getline(temp, 500);
r.weyr = new char[ strlen(temp) +1];
strcpy(r.weyr, temp);
return is;
}
ofstream& operator << (ofstream& os, const Rider& r)
{
os << r.name << endl
<< r.age << endl
<< r.rank << endl
<< r.weyr << endl;
return os;
}
ifstream& operator >> (ifstream& is, Rider & r)
{
char temp[ 500 ];
is.getline(temp, 500);
r.name = new char[ strlen(temp) + 1 ];
strcpy(r.name, temp);
is >> r.age;
is.ignore(100000, '\n');
is.getline(temp, 500);
r.rank = new char[ strlen(temp) + 1];
strcpy(r.rank, temp);
is.getline(temp, 500);
r.weyr = new char[ strlen(temp) + 1 ];
strcpy(r.weyr, temp);
return is;
}
Rider.h
#ifndef RIDER_H
#define RIDER_H
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::boolalpha;
#include <cstring>
using std::strcpy;
using std::strlen;
#include <fstream>
using std::ostream;
using std::istream;
using std::ofstream;
using std::ifstream;
class Rider
{
public:
Rider() = default;
Rider(const char* name, int age, const char* rank, const char* weyr);
void setName(const char* name);
void setRank(const char * rank);
void setWeyr(const char * weyr);
void setAge(int age); // required when we enter a new Rider
// from the keyboard
const char* getName() const { return name; }
const char* getRank() const { return rank; }
const char* getWeyr() const { return weyr; }
int getAge() const { return age; }
friend ostream& operator << (ostream& os, const Rider& r);
friend istream& operator >> (istream& is, Rider& r);
friend ofstream& operator << (ofstream& os, const Rider& r);
friend ifstream& operator >> (ifstream& is, Rider & r);
private:
char * name = nullptr;
char * rank = nullptr;
char * weyr = nullptr;
int age = 0;
};
#endif
오류를 읽고 계하십니까? 'class 'FlyingUnit'에는 'length'라는 필드가 없으므로 나에게 분명합니다. – Kevin
나는 약 400 줄의 전체 오류를 제공 할 수 없다. " 'FlyingUnit'클래스에는 'xxxxx'라는 이름의 멤버가 없다. 모든 것을 위해 – Burgtaro
@Burgtaro이 코드를 개발했다면 더 자주 컴파일하거나 인텔리 센스 IDE. – LogicStuff