在头文件中声明时未知的类型名
Unknown Typename when declared in header
由于一些奇怪的原因,我收到了一个位于头文件中的typedef void变量的未知类型名。自然地,我在网上搜索,虽然可以注意到我发现了类似的问题,但也应该注意到我没有使用IDE,只有Vim和Clang,没有预编译的头文件。在对ctrie_int头的单独测试中,一切都可以编译,但是当我扩展实现并将其头添加到另一个头的实现文件时,我得到了如下所示的奇怪错误。我相信这是一个简单的问题,但我不确定它是什么,有什么建议吗?
clang++ -Wall -Wextra -g -std=c++11 lzwtest.cpp -o lzwtest dict;
Project Compilation
.
.
.
.
.
Compiling CPP file lzwtest.cpp ...
In file included from lzwtest.cpp:2:
In file included from ./LZW.h:23:
In file included from ./ctrie_int.h:36:
./ctrie_int.ii:7:1: error: unknown type name 'Trie_Int'
Trie_Int * newTrie_Int(int defVal){return new Trie<int>(defVal);}
^
./ctrie_int.ii:7:43: error: cannot initialize return object of type 'int *' with an rvalue of type 'Trie<int> *'
Trie_Int * newTrie_Int(int defVal){return new Trie<int>(defVal);}
^~~~~~~~~~~~~~~~~~~~~
./ctrie_int.ii:9:21: error: unknown type name 'Trie_Int'
void deleteTrie_Int(Trie_Int * trie){delete ((Trie<int> *)trie);}
^
./ctrie_int.ii:11:19: error: unknown type name 'Trie_Int'
int Trie_Int_size(Trie_Int * t){return ((Trie<int> *)t)->size();}
^
./ctrie_int.ii:13:30: error: unknown type name 'Trie_Int'
int Trie_Int_getDefaultValue(Trie_Int * t){return ((Trie<int> *)t)->getDefaultValue();}
^
./ctrie_int.ii:15:23: error: unknown type name 'Trie_Int'
int Trie_Int_contains(Trie_Int * t,const char * key){return ((Trie<int> *)t)->contains(key); }
^
./ctrie_int.ii:17:18: error: unknown type name 'Trie_Int'
int Trie_Int_get(Trie_Int * t,char * key){return ((Trie<int> *)t)->get(key); }
^
./ctrie_int.ii:19:19: error: unknown type name 'Trie_Int'
void Trie_Int_put(Trie_Int * t,char * s,int val){ ((Trie<int> *)t)->put(s,val);}
^
./ctrie_int.ii:21:37: error: unknown type name 'Trie_Int'
const char * Trie_Int_longestPrefix(Trie_Int * t,char * s){return ((Trie<int> *)t)->longestPrefix(s).c_str();}
^
./ctrie_int.ii:23:23: error: unknown type name 'Trie_Int'
int Trie_Int_compress(Trie_Int * t){return ((Trie<int> *)t)->compress();}
^
10 errors generated.
下面是要包含的文件的头文件
ctrie_int.h
#ifndef COM_WORDGAME_UTILITY_CTRIE_H
#define COM_WORDGAME_UTILITY_CTRIE_H
#ifdef __cplusplus
extern "C"{ //this is used to identify following code as C specific code which will enforce C style name mangling
#endif
//Declare a new void Type To Emulate C class
typedef void Trie_Int;
...Removed in attempt to shorten Question
#ifdef __cplusplus
}
#endif
#endif
这个文件使用前面但甚至简单的代码,或者只是包含最后一个头文件导致开始
中描述的错误。#ifndef COM_WORDGAME_UTILITY_CTRIE_H
#define COM_WORDGAME_UTILITY_CTRIE_H
#ifdef __cplusplus
extern "C"{ //this is used to identify following code as C specific code which will enforce C style name mangling
#endif
void compress(char src[],char dst[]);
void decompress(char src[],char dst[]);
#ifdef __cplusplus
}
#endif
#endif
//BELOW CODE WILL BE ADDED IN ANOTHER FILE
#include <stdio.h>
#include <stdlib.h>
#include "ctrie_int.h" // This causes an issue cannot find Trie_Int the functions return an odd message describing the Trie_Int was defered to an actual pointer integer
以清晰地显示代码的前几行。它看起来像这样
//#include "ctrie_int.h" //Should not be included would create cycle since ctrie_int.h declares it at the final line
#include "Trie.hpp" //C++ code
//THIS HAS TO BE COMPILED WITH C++ COMPILER TO BE COMPILED PROPERLY ANYWAY GAURDS UNEEDED
extern "C"{
//Create new Trie_Int Object
Trie_Int * newTrie_Int(int defVal){return new Trie<int>(defVal);}
....Removed In Attempt to shorten question
}
线索在错误消息的第一阶段:
Compiling CPP file lzwtest.cpp ...
In file included from lzwtest.cpp:2:
In file included from ./LZW.h:23:
In file included from ./ctrie_int.h:36: <<< Here
./ctrie_int.ii:7:1: error: unknown type name 'Trie_Int'
在 Trie_Int
被定义之前,文件ctrie_int.ii
似乎被包含在您的头中。
相关文章:
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 使用 make 编译 MPI,几个命名空间错误,例如"错误:未知类型名称'使用'?
- 即使直接从官方示例中复制,也找不到未知类型名称QML_ELEMENT和 QML 模块
- 通过 C++ 中的重载构造函数初始化未知类型的变量
- 线程 std::调用未知类型,无法专门化函数错误
- MacOS 上的 LLVM - 标准文件 iosfwd 中未知类型名称'template'
- C++ 未知类型名称,即使类型是通过标头定义的
- 通过模板函数对未知类型调用方法
- 错误:使用 SWIG 的未知类型名称"类"
- C++:将未知类型的对象存储为成员变量的类
- 为什么未知类型名称"Complejo"?
- 在 Mac OS x 中制造期间出现错误未知类型名称"constexpr"
- 查找上下文RPC_NS_HANDLE未知类型名称
- 错误:未知类型名称"功能跟踪"
- C++中的自由定理:模板是否本质上对未知类型的对象无知和中立?
- 未知 使用用于C++代码的标头编译 C 代码时char16_t未知类型名称
- Linux中未知类型名称UINT64_T和UINT16_T UINT8_T
- 如何确定未知类型数组的索引是否为空
- 当我返回节点*时,C++中出现未知类型错误
- 无法编译任何C++程序;错误:未知类型名称'uint8_t'