0
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

1

1 Answer 1

2

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.

1
  • I was a little confused by your wording but understood, it worked like a charm thanks.
    – Malaken
    May 23, 2011 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.