[英]“[Classname] does not name a type” even after including .h file
I get this compiler error("CLASSNAME does not name a type") on every function prototype and fucntion in my .cpp file 我的.cpp文件中的每个函数原型和功能上都出现此编译器错误(“ CLASSNAME不命名类型”)
.h file: .h文件:
#ifndef MOVIETREE_HPP
#define MOVIETREE_HPP
struct MovieNode
{
...//members and such
};
class MovieTree
{
public:
MovieTree();
~MovieTree();
void printMovieInventory();
...//more functions
protected:
private:
void printMovieInventory(MovieNode * node);
MovieNode* search(std::string title);
MovieNode *root;
};
#endif // MOVIETREE_HPP
.cpp file: .cpp文件:
#ifndef MOVIETREE_HPP
#define MOVIETREE_HPP
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include "MovieTree.hpp"
using namespace std;
MovieTree::MovieTree(); //error code here and all prototypes and functions below
MovieTree::~MovieTree();
void MovieTree::printMovieInventory();
...//more function prototypes
MovieTree::MovieTree(){
}
MovieTree::~MovieTree(){
}
void MovieTree::printMovieInventory(){
...//body
}
...//more function bodies
#endif
All other forums and questions I've encountered regarding this has the simple solution of including the header file. 我遇到的所有其他论坛和问题都提供了包含头文件的简单解决方案。 I've already included that in my code.
我已经将其包含在我的代码中。
I've triple checked and am pretty I spelled everything right. 我检查了三遍,很高兴我拼写的一切都正确。 What have I done wrong?
我做错了什么?
The problem is these lines in the .cpp
file: 问题是
.cpp
文件中的这些行:
#ifndef MOVIETREE_HPP
#define MOVIETREE_HPP
...
#endif
These lines should only be put in the header file, not the program file -- they're used by the header to detect if it's included twice so it doesn't try to redefine everything. 这些行仅应放在头文件中,而不是在程序文件中-头文件使用它们来检测是否包含了两次,因此它不会尝试重新定义所有内容。 By setting it yourself before the
#include <movietree.hpp>
line, you fool it into thinking that it has already been included, so it doesn't do anything. 通过自己在
#include <movietree.hpp>
行之前进行设置,您会以为它已经被包含,因此它什么也不做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.