即使在包含 .h 文件后"[Classname] does not name a type"
"[Classname] does not name a type" even after including .h file
我得到这个编译器错误("CLASSNAME不命名类型")在我的。cpp文件中的每个函数原型和函数
. 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文件:
#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
我遇到的所有其他论坛和问题都有包含头文件的简单解决方案。我已经把它包含在我的代码中了。
我已经检查了三遍,很高兴我拼对了。我做错了什么?
问题是.cpp
文件中的这几行:
#ifndef MOVIETREE_HPP
#define MOVIETREE_HPP
...
#endif
这些行应该只放在头文件中,而不是程序文件中——它们被头文件用来检测它是否被包含两次,这样它就不会试图重新定义所有内容。通过在#include <movietree.hpp>
行之前设置它,您可以欺骗它,使其认为它已经被包含在内,因此它不做任何事情。
相关文章:
- 将系数存储在头文件的数组中("does not name a type"错误)
- 当初始值设定项是基类名时'initializer does not name a non-static data member or base class'错误
- 由于"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int",我现在无法编
- 如何解决"'mutex' in namespace 'std' does not name a type"?
- 在 C++ 中使用命名空间时出现"does not name a type"错误
- 已声明时"Does not name a type"错误
- 嵌套类"does not name a type"
- 这在C++ "It does not own the underlying data, and so is cheap to copy or assign"中意味着什么
- Eigen loadMarket does not compile
- 为什么当我的代码超出函数范围时,"does not name a type"出现编译器错误?
- 创建C++ Redis 模块 - "does not export RedisModule_OnLoad() symbol"
- 无法分隔标头类。我得到"does not name a type"
- 模板元编程:"does not have integral or enumeration type"
- 如何修复类函数"prototype does not match"和"cadidate is"错误
- #define 的"Declaration does not declare anything"错误
- 修复第三方代码:"error: ‘enable_if’ in namespace ‘std’ does not name a template type"
- 在 c++ 中,如果包含标头,为什么我会收到'does not a name of type'错误?
- 什么原因导致我的"‘FatalError’ in namespace ‘Foam’ does not name a type"错误?
- C++ 迭代器错误"does not refer to a value"
- 编译错误"String does not name a type"