函数和类错误
class BufferFile{
public:
BufferFile(IOBuffer &);
int Open(char *);
int Create(char *);
int Close();
int Rewind();
int Read(int recaddr = -1);
int Write(int recaddr = -1);
int Append();
IOBuffer & GetBuffer();
protected:
IOBuffer & Buffer;
std::fstream File;
int HeaderSize;
int ReadHeader();
int WriteHeader();
};
BufferFile::BufferFile(IOBuffer & from):Buffer(from){}
int BufferFile::Read(int recaddr){
if(recaddr==1) return Buffer.Write(File);
else return Buffer.DWrite(File, recaddr);
}
int BufferFile::Append(){
File.seekp(0,std::ios::end);
return Buffer.Write(File);
}
IOBuffer & BufferFile::GetBuffer(){
return Buffer;
}
int BufferFile::ReadHeader(){
return Buffer.ReadHeader(File);
}
int BufferFile::WriteHeader(){
return Buffer.WriteHeader(File);
}
我从 IOBuffer 字段收到几个错误,说它没有在函数作用域中声明,或者在构造函数上的“&”标记之前“预期为‘)’,是什么导致了这些错误?
以下是该项目涉及到的所有文件: Person.h!
Buffile.cpp
BuffFile.h
Delim.cpp
Delim.h
Fixfld.cpp
Fixfld.h
FixLen.cpp
FixLen.h
Iobuffer.cpp
Iobuffer.h
Length.cpp 长度.h
Varlen.cpp
Varlen.h
class BufferFile{
public:
BufferFile(IOBuffer &);
int Open(char *);
int Create(char *);
int Close();
int Rewind();
int Read(int recaddr = -1);
int Write(int recaddr = -1);
int Append();
IOBuffer & GetBuffer();
protected:
IOBuffer & Buffer;
std::fstream File;
int HeaderSize;
int ReadHeader();
int WriteHeader();
};
BufferFile::BufferFile(IOBuffer & from):Buffer(from){}
int BufferFile::Read(int recaddr){
if(recaddr==1) return Buffer.Write(File);
else return Buffer.DWrite(File, recaddr);
}
int BufferFile::Append(){
File.seekp(0,std::ios::end);
return Buffer.Write(File);
}
IOBuffer & BufferFile::GetBuffer(){
return Buffer;
}
int BufferFile::ReadHeader(){
return Buffer.ReadHeader(File);
}
int BufferFile::WriteHeader(){
return Buffer.WriteHeader(File);
}
I am getting several errors form the IOBuffer field, saying that it was not declared in the function scopes or "expected `)' before ‘&’ token" on the constructor, what is causing these?
Here are all the files involved in this project:
Person.h!
Buffile.cpp
BuffFile.h
Delim.cpp
Delim.h
Fixfld.cpp
Fixfld.h
FixLen.cpp
FixLen.h
Iobuffer.cpp
Iobuffer.h
Length.cpp
Length.h
Varlen.cpp
Varlen.h
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的问题是这样的(来自 Buffile.h):
...该逻辑破坏了 Iobuffer.h 中的类似/冗余逻辑:
问题是 Iobuffer.h 中的“class IOBuffer”声明永远不会被解析,因为编译器值 IOBUFFER 已在 Buffile.h 中定义,因此 Iobuffer.h 顶部的 #ifndef IOBUFFER 未激活。
正确的方法是修改 Buffile.h 以仅包含 #include "Iobuffer.h" 行,并将其留给 Iobuffer.h 的内容来执行 #ifndef 和 #define 操作。
I think your problem is this (from Buffile.h):
... that logic breaks the similar/redundant logic that you have in Iobuffer.h:
The problem is that the declaration of "class IOBuffer" in Iobuffer.h is never parsed, because the compiler value IOBUFFER was already defined inside Buffile.h, and thus the #ifndef IOBUFFER at the top of Iobuffer.h is not activated.
The right way to do it is to modify Buffile.h to include only the #include "Iobuffer.h" line, and leave it up to the contents of Iobuffer.h to do the #ifndef and #define stuff.