# [C++] Annoying C2248 Error

This topic is 2838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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.

##### Share on other sites

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.

##### Share on other sites
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.

##### Share on other sites
trying using std::string instead of std::wstring

##### Share on other sites

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.

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites

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

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.

##### Share on other sites
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.

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633763
• Total Posts
3013728
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!