Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error C2248: cannot access private member declared in class

Tags:

c++

I´m getting this error in a c++ application:

error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' :
              cannot access private member declared in class '

I have seen similar questions in stackoverflow, but I couldn't figure out what's wrong with my code. Can someone help me?

    //header file
class batchformat {
    public:
        batchformat();
        ~batchformat();
        std::vector<long> cases;        
        void readBatchformat();
    private:
        string readLinee(ifstream batchFile);
        void clear();
};


    //cpp file
void batchformat::readBatchformat() 
{
    ifstream batchFile; 
    //CODE HERE
    line = batchformat::readLinee(batchFile);

}


string batchformat::readLinee(ifstream batchFile)
{
    string thisLine;
    //CODE HERE
    return thisLine;
}
like image 543
guilhermecgs Avatar asked Dec 04 '22 10:12

guilhermecgs


2 Answers

The problem is:

string readLinee(ifstream batchFile);

This tries to pass a copy of the stream by value; but streams are not copyable. You want to pass by reference instead:

string readLinee(ifstream & batchFile);
//                        ^
like image 140
Mike Seymour Avatar answered Dec 07 '22 01:12

Mike Seymour


string batchformat::readLinee(ifstream batchFile)

is trying to copy the ifstream Take it by ref instead

string batchformat::readLinee(ifstream& batchFile)
like image 29
doctorlove Avatar answered Dec 07 '22 00:12

doctorlove