尚未声明 C++ 'class' - 将类传递给类
c++ 'class' has not been declared - passing a class to a class
所以目前我正在尝试在<translator>
类中运行一个方法,方法是从我的 main.cpp 向它传递一个<bintree>
类的实例。以下是我的代码,我在底部收到错误。我确定我只是缺少传递参数的某些方面,但对于我的生活,我无法弄清楚。
主线.cpp(它创建bintree和传递的区域)最相关的底线
if (validFile == true)
{
//Create bintree through insert. Rebalance follows
bintree<morseNode> morseTree;
for (int count = 0; count < 26; count++)
{
char letter = morseCodes[count].letter;
string code = morseCodes[count].code;
morseNode node;
node.letter = letter;
node.code = code;
morseTree.insert(node);
}
morseTree.rebalance();
translator fileTranslator(outputFile);//create instance of translator
//Read and translate files based on conversion type
if (translatorType != "e" || translatorType != "E") //English -> Morse Conversion
{
validFile = readFile(inputFile, translatorType, morseCodes, inputList);
if (validFile == true)
{
fileTranslator.engToMorseTranslation(inputList, morseCodes);
}
}
else //Morse -> English Conversion
{
validFile = readFile(inputFile, translatorType, morseCodes, inputList);
if (validFile == true)
{
fileTranslator.morseToEngTranslation(inputList, morseTree);
//Here is where it sends morseTree that is throwing ^^ the error.
}
}
我通过translator.h接收它(编辑:它知道morseNode的常量)
#ifndef TRANSLATOR_H
#define TRANSLATOR_H
#include <string>
#include <iostream>
#include <list>
//I tried #include "bintree.h" here. this did not work
using namespace std;
class translator
{
private:
string outName;
list<char> morseOutput;
public:
void morseToEngTranslation(list<char> &myList, bintree<morseNode> &myTree)
{
//functions here.. seemed irrelevant as i just wanted to show how i am
//receiving the parameters
}
};
#endif
宾特里不是我的,它是提供的。 起始声明如下。它很长,函数本身对这个问题并不重要,所以我不会包括它们。
#ifndef BINTREE_H_
#define BINTREE_H_
#include <stdexcept>
namespace treespc
{
// forward class declaration
template <typename dataType> class bintree;
template <typename dataType> class binnode;
#include "const_iterator.h"
#include "binnode.h"
/********************************************************
template class for a binary tree
********************************************************/
template <typename dataType> class bintree
{
public:
//....
private:
//....
};
}
我收到的错误是:
translator.h:79:52: error: ‘bintree’ has not been declared
void morseToEngTranslation(list<char> &myList, bintree<morseNode> &myTree)
translator.h:79:59: error: expected ‘,’ or ‘...’ before ‘<’ token
void morseToEngTranslation(list<char> &myList, bintree<morseNode> &myTree)
提前感谢任何至少能为我指出正确方向的人:)
使用 using namespace treespec
或 treespc::bintree
给出 bintree 的命名空间
#ifndef TRANSLATOR_H
#define TRANSLATOR_H
#include <string>
#include <iostream>
#include <list>
#include "bintree.h"
using namespace std;
class translator
{
private:
string outName;
list<char> morseOutput;
public:
void morseToEngTranslation(list<char> &myList, treespc::bintree<morseNode> &myTree)
{
//functions here.. seemed irrelevant as i just wanted to show how i am
//receiving the parameters
}
};
#endif
ifndef BINTREE_H_
#define BINTREE_H_
你在这里错过了#
吗?
更新:您必须包含bintree标头或使用前向声明(请注意,因为您的类在命名空间内)请参阅此处的答案:为什么我不能在这样的命名空间中向前声明一个类?
相关文章:
- #ifdef和未声明的标识符
- 未声明的标识符编译暗黑破坏神 2 程序"muleview"
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- Google protobuf 时间戳未声明标识符,在 Windows 上具有C++
- 在气泡排序程序中未声明错误功能
- 我在范围内未声明的错误类有问题
- 使用未声明的标识符"sqrt"?
- 我包含了<winuser.h>,但编译器在MonitorFromWindow上抛出"未声明"
- 对类 (C++) 中的私有变量使用未声明的标识符
- 我的代码中有错误,未声明的标识符
- 未定义的标识符/未声明
- 错误:在 C++ 'std'使用未声明的标识符
- 在编译器之前检测未声明的标识符
- 使用未声明的标识符'temp'
- 使用未声明的标识符"yylex"和"yyin"?
- 使用"class"关键字,后跟未声明的标识符
- 未声明的标识符错误,但变量定义正确 (?)
- C2065:'class'未声明的标识符,包括标头
- C++:[class]未在此作用域中声明
- C++ 无意义的错误:c2629 "Unexpected class"、c2065:'ceil'未声明的标识