Sign in to follow this  
rage989

error 'std::basic_ios_Elem,_Traits::basic_ios' : cannot access private membe

Recommended Posts

I am getting the following error when i build my project. i am just using ifstream file to declare my file variables. and file.open("file.txt",ios::in) please help. c:\program files\microsoft visual studio 8\vc\include\fstream(675) : error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>' with [ _Elem=char, _Traits=std::char_traits<char> ] c:\program files\microsoft visual studio 8\vc\include\ios(151) : see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios' with [ _Elem=char, _Traits=std::char_traits<char> ] This diagnostic occurred in the compiler generated function 'std::basic_ifstream<_Elem,_Traits>::basic_ifstream(const std::basic_ifstream<_Elem,_Traits> &)' with [ _Elem=char, _Traits=std::char_traits<char> ]

Share this post


Link to post
Share on other sites
okay i got rid of that error, thanks. but now i am sending a pointer and i get this error


error C2296: '>>' : illegal, left operand has type 'std::ifstream *'

here is some of my code:
ifstream file;
file.open(fileName,ios::in);
widgets[i]->createDisplayBox(&file);

void Widgets::createDisplayBox(ifstream *file){
float tempFloat;
uByte ubyte;
uShort ushort;
if (file->is_open())
{
displayBox->setWidth(&width);
displayBox->setHeight(&height);

file>>ushort;
displayBox->setId(ushort);
file>>ushort;
.....

Share this post


Link to post
Share on other sites
Use a reference:

widgets[i]->createDisplayBox( file );
void Widgets::createDisplayBox( ifstream & file ) { ... }


Also, you may want to use an istream instead of an ifstream if ever you want to use another type of input stream.


jfl.

Share this post


Link to post
Share on other sites
If your function takes a reference to a ifstream, you can only pass file streams to your function. Make the parameter of type istream instead and you can pass any input stream derived from the common standard input stream interface. You could pass an ifstream object (a file), an istringstream object (memory stream), cin (take the input from the console; my image library can even load image data you type from the keyboard without any extra work), any user defined input stream (I have made streams that can read from a network connection and from ZIP files for example); anything derived from istream.

Why tie your function to files only when it, by just removing one single letter, can work just as well with any arbitrary input stream.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this