标头不起作用,“类未在此范围内声明”

时间:2019-04-06 04:50:24

标签: c++ templates header

我正在尝试实现2个互相用作其方法自变量的类,但是遇到一些编译错误,指出这些类未定义。

这是我的班级光盘,正在使用班级

//class Disc
#ifndef DISC
#define DISC
#include <iostream>
#include <string>
#include "LinkedList.h"
#include "Track.h"
#include <memory>
using namespace std;

class Disc{
 private:
  string title;
  string artist;
  int year;
  string genre;
  int totalPlayTime;
  bool multiArtist;
  make_unique <Track> LinkedList;
 public:
  int y;
};
#endif

这是我的班级Track,它也使用Disc类。

//class TRACK
#ifndef TRACK
#define TRACK

#include <iostream>
#include <string>
#include "Disc.h"
#include <memory>
using namespace std;

class Track{
 private:
  string name;
  string artist;
  int playTime;
  int number;
  string location;
  shared_ptr <Disc> discPtr;
 public:
  Track()=default;
  Track(shared_ptr <Disc> discP);
  void printTrack() const;
  bool isLessThan(Track) const;
  int getNumber() const;
  int getPlayTime() const;
  Track getTrackFromUser();
};
#include "Track.cpp"
#endif

这些是我得到的错误:


Track.h:18:15: error: ‘Disc’ was not declared in this scope
   shared_ptr <Disc> discPtr;
               ^
Track.h:18:19: error: template argument 1 is invalid
   shared_ptr <Disc> discPtr;
                   ^
Track.h:21:21: error: ‘Disc’ was not declared in this scope
   Track(shared_ptr <Disc> discP);
                     ^
Track.h:21:25: error: template argument 1 is invalid
   Track(shared_ptr <Disc> discP);
                         ^
Track.cpp:6:26: error: ‘Disc’ was not declared in this scope
   Track::Track(shared_ptr <Disc> DiscP){
                          ^
Track.cpp:6:30: error: template argument 1 is invalid
   Track::Track(shared_ptr <Disc> DiscP){
                              ^

请帮助我。 我不知道如何在两个文件中都包含两个标头

0 个答案:

没有答案