[C++] Annoying C2248 Error

Started by
19 comments, last by Antheus 13 years, 1 month ago
Hello,

i am getting this


c:\program files\microsoft visual studio 10.0\vc\include\istream(860): error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ios(176) : see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> This diagnostic occurred in the compiler generated function 'std::basic_istream<_Elem,_Traits>::basic_istream(const std::basic_istream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>



it seems to be occurring in this function:


void SurviveHeightmap::LoadRAW( int m, int n, const std::wstring &fileName, float heightScale, float heightOffset )
{
m_heightmapFilename = fileName;
m_heightScale = heightScale;
m_heightOffset = heightOffset;

std::vector< unsigned char > in( m * n );

std::ifstream inFile;
inFile.open( fileName.c_str( ), std::ios::in | std::ios::binary );

if ( !inFile )
{
MessageBox( NULL, L"Could not open heightmap file.", L"Survive", NULL );
return;
}

inFile.read( ( char * )&in[ 0 ], ( std::streamsize ) in.size( ) );

inFile.close( );

m_heightMap.Resize( m, n, 0.0f );

for ( int i = 0; i < m; ++i )
{
for ( int j = 0; j < n; ++j )
{
int k = i * n + j;
m_heightMap( i, j ) = ( float ) in[ k ] * heightScale + heightOffset;
}
}

filter3x3( );
}



In case you don't know, this code reads a heightmap from a RAW file.

I've looked for days on Google trying to figure out that error, but all the threads I've seen say "don't pass a stream by value, pass by reference!" The problem is, I'm not passing any streams, so I don't know where this would come from.

This is the only error the compiler generates.

Thanks in advance!
"Welcome to the desert of the real." -- Morpheus, The Matrix.
Advertisement
The problem may be that you're using a reserved word for a variable name.

I.e., you named your vector in. Change it to buf or some other non-reserved-word name.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


The problem may be that you're using a reserved word for a variable name.

I.e., you named your vector in. Change it to buf or some other non-reserved-word name.


I tried that and it didn't work.
"Welcome to the desert of the real." -- Morpheus, The Matrix.
What headers are you including? The example code I found for ifstream includes <iostream> and <fstream>, so if you aren't including those you might be working with an incomplete declaraction of ifstream.
trying using std::string instead of std::wstring

trying using std::string instead of std::wstring

Recent versions of Visual C++ have additional constructors in the [o|i]fstream classes that take wide character strings. This very likely isn't the problem.

fireshadow4126: the following reduced code compiles just fine for me using Visual C++ 2010:


#include <vector>
#include <iostream>
#include <fstream>
#include <string>

#define UNICODE 1
#include <windows.h>

void LoadRAW( int m, int n, const std::wstring &fileName, float heightScale, float heightOffset )
{
//m_heightmapFilename = fileName;
//m_heightScale = heightScale;
//m_heightOffset = heightOffset;

std::vector< unsigned char > in( m * n );

std::ifstream inFile;
inFile.open( fileName.c_str( ), std::ios::in | std::ios::binary );

if ( !inFile )
{
MessageBox( NULL, L"Could not open heightmap file.", L"Survive", NULL );
return;
}

inFile.read( ( char * )&in[ 0 ], ( std::streamsize ) in.size( ) );

inFile.close( );

//m_heightMap.Resize( m, n, 0.0f );

for ( int i = 0; i < m; ++i )
{
for ( int j = 0; j < n; ++j )
{
int k = i * n + j;
//m_heightMap( i, j ) = ( float ) in[ k ] * heightScale + heightOffset;
}
}

//filter3x3( );
}


Does it work for you? If so, can you simmer down your code to the smallest point where the error is still apparent? This will very likely lead you to the point of failure.

Actually what makes you think the error is in this function? The error you posted doesn't mention your code at all.

It may be the case that a macro introduced by one of your headers is causing trouble.
I included <iostream> and <fstream>, so that isn't the problem. I reduced the code like you did and I still got the error, so it probably isn't in that function. However, VS spits out the error after showing 'SurviveHeightmap.cpp' in the output, so it's probably in something related to that file. I checked my includes and I have no macros except for the #ifdef at the top that prevents multiple-inclusion.
"Welcome to the desert of the real." -- Morpheus, The Matrix.
The full error message will contain something like "instantiated in ...", which should point back to the actual source of error. The error message posted above is missing the important parts.

I included <iostream> and <fstream>, so that isn't the problem. I reduced the code like you did and I still got the error, so it probably isn't in that function.

Can you compile the exact code I gave you? i.e. copy and paste it in to a source file and do:

cl /EHsc /nologo /c thefile.cpp

Other questions that might help you to pin-point the error:

Can you comment out the function entirely and get the code to compile?
If not, does commenting out the entire source file yield success?

You can see where I'm going here, I hope. It's not hard to reduce the amount of code that could possibly be responsible for the error.


However, VS spits out the error after showing 'SurviveHeightmap.cpp' in the output, so it's probably in something related to that file. I checked my includes and I have no macros except for the #ifdef at the top that prevents multiple-inclusion.
[/quote]

Well I'm afraid it's then up to you to reduce the code to get it to the smallest point at which the error is still apparent, using the kind of techniques I outlined above. None of us have your project files or your code, so it's unlikely we can help much further until you're able to provide more specifics.

For what it's worth, the compiler error is indeed consistent with trying to copy an std::istream of some kind.
Here's the full build output:


1>------ Build started: Project: SurviveLib, Configuration: Debug Win32 ------
1>Build started 3/12/2011 1:38:14 PM.
1>InitializeBuildStatus:
1> Touching "Debug\SurviveLib.unsuccessfulbuild".
1>ClCompile:
1> SurviveGameExecutor.cpp
1> SurviveHeightmap.cpp
1>c:\program files\microsoft visual studio 10.0\vc\include\istream(860): error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\ios(176) : see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> This diagnostic occurred in the compiler generated function 'std::basic_istream<_Elem,_Traits>::basic_istream(const std::basic_istream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:04.48
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========




As you can see, there's no 'instantiated in' as you say.
"Welcome to the desert of the real." -- Morpheus, The Matrix.

This topic is closed to new replies.

Advertisement