【发布时间】:2016-04-25 13:22:27
【问题描述】:
我是 C++ 和一般编程的新手。我必须在“NAVI”类中为我的课程编写一个程序,该程序将指向“Ort”类型的对象的指针(trans:Location)存储在列表中。 (“Navi”类还有更多功能,但请忽略它们)。它必须是一个列表,即使在我的情况下向量会更有意义。
编译时遇到的错误:
In file included from Ort.h:10:0,
from Ort.cpp:8:
NAVI.h:40:10: error: 'Ort' was not declared in this scope
list<Ort> *n;
^
NAVI.h:40:13: error: template argument 1 is invalid
list<Ort> *n;
^
NAVI.h:40:13: error: template argument 2 is invalid
我的“Navi.h”标题:
#ifndef NAVI_H
#define NAVI_H
#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>
#include <list>
#include "Ort.h"
#include <vector>
#include <sstream>
using namespace std;
class NAVI {
public:
NAVI();
NAVI(const NAVI& orig);
virtual ~NAVI();
virtual void RouteBerechnen();
void namenAnVektor(string n, int x);
void namenAusVektorLoeschen(string st);
void namenInDatei();
void NamenEinlesen();
void AlleAusgeben();
void alleDatenBinaerSpeichern();
void alleDatenBinaerLaden();
void nachOrtSuchen(string start, string ziel);
private:
list<Ort> *n;
const std::string binaerPfad = "C:\\Users\\Karsten\\Desktop\\Skripte u. Unterlagen\\2. Semester\\PAD 2\\Praktikum\\binaerdaten.bin";
const std::string dateiPfad = "C:\\Users\\Karsten\\Desktop\\Skripte u. Unterlagen\\2. Semester\\PAD 2\\Praktikum\\schreiben.txt";
};
#endif /* NAVI_H */
我的“Ort.h”:
#ifndef ORT_H
#define ORT_H
#include "NAVI.h"
class Ort {
public:
Ort(int cords,std::string n);
Ort();
Ort(const Ort& orig);
virtual ~Ort();
std::string getName();
int getCords();
void setCords(int cords);
void setName(std::string n);
private:
int GPSKoordinaten;
std::string Ortsname;
};
#endif /* ORT_H */
非常感谢任何帮助:)
【问题讨论】:
-
为什么
Ort.h包含Navi.h? -
你说得对,没有理由在 Navi.h 中包含 Ort.h - 不知道我为什么这样做。这也解决了我的错误,但为什么呢? :) 和 tyvm!