所以我在试图编译类的.cc文件时一直收到这个错误。这是我的.cc代码和.hh代码:
.hh:
#ifndef BINTREE_IO_PARINT_HH
#define BINTREE_IO_PARINT_HH
#include "BinTree.hh"
#include "ParInt.hh"
#include <iostream>
void read_bintree_parint(BinTree<ParInt>& a);
void write_bintree_parint(const BinTree<ParInt>& a);
#endif
.cc:
#include "BinTreeIOParInt.hh"
void read_bintree_parint(BinTree<ParInt>& a){
ParInt x;
BinTree<ParInt> a1;
BinTree<ParInt> a2;
x.llegir();
if(x.primer() != 0 and x.segon() != 0){
read_bintree_parint(a1);
read_bintree_parint(a2);
a.BinTree(x, a1, a2);
}
}
void write_bintree_parint(const BinTree<ParInt>& a){
ParInt x;
if(not a.empty()){
BinTree<ParInt> a1 = a.left();
BinTree<ParInt> a2 = a.right();
x = a.value();
write_bintree_parint(a1);
cout<<" ";
x.escriure();
write_bintree_parint(a2);
a.BinTree(x, a1, a2);
}
}
我得到的错误是:
> BinTreeIOParInt.cc:4:1: error: expected constructor, destructor, or type conversion before ‘void’
void read_bintree_parint(BinTree<ParInt>& a){
如果有人知道发生了什么,请解释。
谢谢大家
我的玻璃球说你忘了在ParInt.hh的末尾放一个分号。你可能想提供这两个头的源代码,因为没有它们很难调试。
当您执行#include …
时,编译器会将文件的内容放在#inculde
的位置(好吧,几乎有一些微妙的事情涉及行号和文件名,但您可以忽略它们(。
由于您有时会收到错误所在行下面的错误消息。#include
也可能发生这种情况,因此错误可能在其中一个包含的文件中。