C++头和cpp文件fpermisive
C++ header and cpp file fpermisive
我真的很缺时间,我不知道我做错了什么。
我试图将3个类对象链接在一起,但我总是出错,在互联网上找不到任何答案。
我想知道如何正确地制作.h和.cpp文件。
也许你们中的一些人会看到我做错了什么。顺便说一下,我想把代码分开。
第1版:这是我得到的错误,我的错误:在recette/ListRecettes.cpp:8:0:recette/ListRecettes.h:23:42:erreur:ISO C++禁止声明没有类型[-fpermission]的"ajouterRecette"
第2版:ISO C++禁止声明没有类型的"ajouterRecette"[-fpermission]同样的事情编辑3:对不起,评论中的文件名不正确。
这里是标题
/*
* File: ListeRecettes .h
* Author: Necro
*
* Created on November 17, 2015, 1:51 PM
*/
#ifndef LISTERECETTES_H
#define LISTERECETTES_H
#include <vector> //for std::vector
#include "iostream"
#include "Recette.h"
class ListeRecettes {
private:
std::vector<Recette*> recettes;
public:
ListeRecettes();
ListeRecettes(const ListeRecettes& orig);
void ajouterRecette(const Recette& recette);
void enleverRecette(const Recette& recette);
void afficher();
virtual ~ListeRecettes();
};
#endif /* RECETTES_H */
这里是.cpp
/*
* File: ListeRecettes .cpp
* Author: Necro
*
* Created on November 17, 2015, 1:51 PM
*/
#include "ListeRecettes.h"
#include <vector> //for std::vector
#include "iostream"
ListeRecettes::ListeRecettes() {
}
ListeRecettes::ListeRecettes(const ListeRecettes& orig) {
}
ListeRecettes::ajouterRecette(const Recette& recette) {
this->recettes.push_back(recette);
}
ListeRecettes::enleverRecette(const Recette& recette) {
for (int i = 0; i < recettes.size(); i++) {
if (recettes.at(i).getNom() == recette.getNom()) {
recettes.erase(i);
}
}
}
ListeRecettes::afficher(){
for(int i = 0 ; i < recettes.size(); i ++){
std::cout << recettes.at(i).getNom();
}
}
ListeRecettes::~ListeRecettes() {
}
第4版:Recette.h
/*
* File: Recette.h
* Author: Necro
*
* Created on November 17, 2015, 3:14 PM
*/
#ifndef RECETTE_H
#define RECETTE_H
#include <vector> //for std::vector
#include "Ingredient.h"
#include "iostream"
using namespace std;
class Recette {
public:
Recette();
Recette(const Recette& orig);
Recette(string& , Ingredient&);
string getNom();
Ingredient getIngredient();
virtual ~Recette();
private:
string nom;
vector<Ingredient*> listeIngredients;
};
#endif /* RECETTE_H */
Recette.cpp
/*
* File: Recette.cpp
* Author: Necro
*
* Created on November 17, 2015, 3:14 PM
*/
#include "Recette.h"
#include "iostream"
using namespace std;
Recette::Recette() {
}
Recette::Recette(string& nom, Ingredient ingredient) {
this->nom = nom;
this->listeIngredients.push_back(ingredient);
}
Recette::Recette(const Recette& orig) {
}
Recette::getNom(){
return this->nom;
}
Recette::getIngredient(){
return this->listeIngredients;
}
Recette::~Recette() {
}
成分.h
/*
* File: Ingredient.h
* Author: Necro
*
* Created on November 17, 2015, 2:18 PM
*/
#ifndef INGREDIENT_H
#define INGREDIENT_H
#include <iostream>
using namespace std;
class Ingredient {
public:
Ingredient();
Ingredient(string&,int);
Ingredient(const Ingredient& orig);
void addIngredient(int quantite);
void removeIngredient(int quantite);
virtual ~Ingredient();
private:
string nom;
int quantite;
};
#endif /* INGREDIENT_H */
入口.cpp
/*
* File: Ingredient.cpp
* Author: Necro
*
* Created on November 17, 2015, 2:18 PM
*/
#include "Ingredient.h"
Ingredient::Ingredient() {
}
Ingredient::Ingredient(string &nom, int quantite) :
nom(nom), quantite(quantite) {
this->nom = nom;
this->quantite = quantite;
}
Ingredient::Ingredient(const Ingredient& orig) {
}
Ingredient::addIngredient(int quantite) {
this->quantite += quantite;
}
Ingredient::removeIngredient(int quantite){
this->quantite -= quantite;
}
Ingredient::~Ingredient() {
}
您的签名肯定是错误的。
除了构造函数和析构函数之外,您必须每隔定义一次返回类型。
这样的东西:
void ajouterRecette(const Recette& recette);
void enleverRecette(const Recette& recette);
void afficher();
然后相应地更新cpp。
然后你可以发布错误!
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 文本文件中的单词链表
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用新行和不使用新行读取文件
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 挂起和取消挂起一个文件DLL
- 如何确定我已使用非编码文件到达 EOF?
- 命名空间中具有.h和.cpp文件的类
- 如何使用ndk-build.cmd构建Android.so文件
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 读取文件并输入到矢量中
- 在C++中查找文件
- c++库的公共头文件中应该包含什么
- 用c++从输入文件中读取另一行
- Cppcheck生成xml转储文件
- 读取文件的最后一行并输入到链接列表时出错
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- 如何将内容数组写入文本文件?
- C++头和cpp文件fpermisive