和我奋斗的功能,它应该返回对象的向量,但由于某种原因,它始终抛出错误,告诉我的对象是未声明的标识符和此对象的向量是无效的模板和指向我声明函数的.h文件。 我会适当解释这是什么意思,以及如何解决这个问题。以下是我放置我的课程代码并启动文件的代码。C++如何声明函数返回对象的向量
#ifndef SETUPW_H
#define SETUPW_H
#include"Square.h"
#include <iostream>
#include<string>
#include<fstream>
#include<vector>
std::vector<std::ifstream> allText();
std::ifstream loadTxt(std::string txt);
void printByLine(std::ifstream& txt);
std::vector<square> allSquares();//compiler points me to this line and that one bellow
void whichSQ(int sqNum, std::vector<square> sq);
#endif
和我的课:
#ifndef SQUARE_H
#define SQUARE_H
#include"player.h"
#include"setupW.h"
#include<iostream>
#include<string>
#include<fstream>
class square
{
public:
square(std::string name, int sqNumber, std::string description, int exits, int object);
void loadSQ(std::ifstream& inFile);
void printSQ();
private:
int mSqNumber;
std::string mName;
std::string mDescription;
int mExits;
int mObject;
};
#endif
'std :: vector'要求类是可复制的。只需定义一个拷贝构造函数。 –
你的头卫兵在第一个片段中是错误的。如果这是第一个片段,'square.h'不应该包含'setupW.h'。 – Mat
@GuilhermeBernal,除非明确做出不可复制的内容,否则所有类都是可复制的(可能在逻辑上不正确)。 – StoryTeller