开发者

Function and Class errors

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

开发者_如何学Python Length.cpp Length.h

Varlen.cpp

Varlen.h


I think your problem is this (from Buffile.h):

#ifndef IOBUFFER
#define IOBUFFER
#include "Iobuffer.h"
#endif

... that logic breaks the similar/redundant logic that you have in Iobuffer.h:

#ifndef IOBUFFER
#define IOBUFFER
class IOBuffer{
[...]
#endif

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜