| | |
Error C2248 - Clueless
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jul 2009
Posts: 53
Reputation:
Solved Threads: 0
Hey All, i'm doing this project in c++ consisting in reading an mp3 file and extracting the informations within it. Thing is i'm starting to be pissed by this persistent error that stops me from test the code.
This error is, as far as my (limited) knowledge goes, caused by the passing of a stream parameter to a function by copy. Considering that, i'm passing the parameters by reference, but still the error subsists...
I would be very grateful if someone give me a hand here. Thanks in advance, here's the code:
header :
implementation:
The error message goes:
1>------ Build started: Project: Trabalho2, Configuration: Debug Win32 ------
1>Compiling...
1>Mp3.cpp
1>FrameVisitor.cpp
1>c:\program files\microsoft visual studio 8\vc\include\fstream(933) : 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 8\vc\include\ios(151) : 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_fstream<_Elem,_Traits>::basic_fstream(const std::basic_fstream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>Generating Code...
1>Build log was saved at "file://c:\Users\Bruno\Desktop\ISEL\PICC\Trabalhos\Trabalho2\Trabalho2\Debug\BuildLog.htm"
1>Trabalho2 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This error is, as far as my (limited) knowledge goes, caused by the passing of a stream parameter to a function by copy. Considering that, i'm passing the parameters by reference, but still the error subsists...
I would be very grateful if someone give me a hand here. Thanks in advance, here's the code:
header :
C++ Syntax (Toggle Plain Text)
#endif #ifndef VISITOR_H #define VISITOR_H #include <stdio.h> #include <sstream> #include <fstream> #include <list> using namespace std; class FrameVisitor : public Frame { list<Frame> frames; public: FrameVisitor(); list<Frame> get_frames(fstream& file); bool getFirstFrame(Frame& f); void WriteFrame(Frame f, FILE * dst); int fastValidation(Frame f); }; #endif
implementation:
C++ Syntax (Toggle Plain Text)
#include "Mp3.h" using namespace std; FrameVisitor::FrameVisitor() { Frame(); frames = get_frames(myfile); } void FrameVisitor::WriteFrame(Frame f, FILE * dst) { size_t num_bytes = f.getLength(); //size_t size var de instancia de Frame. memcpy(dst,f.frame,num_bytes); //Duvida: É preciso criar um novo file com o mm nome, escrever la a frame e depois o resto? //ou basta escrever por cima como tou a fazer aqui? } list<Frame> FrameVisitor::get_frames(fstream& myfile) { char * memblock = new char [4]; //1º 4 bytes da frame...header. char * start = memblock; int i = 0; char c; list<Frame> lst; Frame f; while(!myfile.eof()){ while(i<4){ c=myfile.get(); f.addByte(c); memblock[i++]=c; } myfile.seekg(-4,ios::cur); i = 0; if((memblock[0] == 0xFF) && ((memblock[1])& 0xE0) == 0xE0) { f.getFrame(myfile);//Pedaço do ficheiro ate encontrar prox header. //Construir uma frame para meter na lista. if(fastValidation(f) == 0) { lst.push_back((f)); memblock = start; } else { f.clear(); memblock = start; myfile.seekg(1,ios::cur); } } myfile.seekg(1,ios::cur); memblock = start; f.clear(); } return lst; } int FrameVisitor::fastValidation(Frame f) { if((f.getVersion() ==1) || (f.getLayer() == 0) || (f.getBitrate() == 0 || f.getBitrate() == 15) || (f.getFrequency() == 3)) return -1; return 0; } bool FrameVisitor::getFirstFrame(Frame& f) { if(!frames.empty()) { f = frames.front(); return true; } return false; }
The error message goes:
1>------ Build started: Project: Trabalho2, Configuration: Debug Win32 ------
1>Compiling...
1>Mp3.cpp
1>FrameVisitor.cpp
1>c:\program files\microsoft visual studio 8\vc\include\fstream(933) : 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 8\vc\include\ios(151) : 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_fstream<_Elem,_Traits>::basic_fstream(const std::basic_fstream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>Generating Code...
1>Build log was saved at "file://c:\Users\Bruno\Desktop\ISEL\PICC\Trabalhos\Trabalho2\Trabalho2\Debug\BuildLog.htm"
1>Trabalho2 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited by Nogat21; Aug 11th, 2009 at 11:19 am.
•
•
Join Date: Jun 2006
Posts: 147
Reputation:
Solved Threads: 20
I've few questions,
you have passed 'myfile' as a parameter in fstream where it is defined?
change the following Code.
Try to pass the filePath not the streams between functions
just open the stream where required and close it after using.
as far as the problem is concerned there is no copy constructor defined for streams, whenever pass by value they'll cause problems.
check your code of class frame as well. rather than storing the stream as a member keep the file path as a member.
Hope this helps.
C++ Syntax (Toggle Plain Text)
FrameVisitor::FrameVisitor() { Frame(); frames = get_frames(myfile); }
change the following Code.
C++ Syntax (Toggle Plain Text)
list<Frame> FrameVisitor::get_frames(fstream& myfile) { char * memblock = new char [4]; //1º 4 bytes da frame...header. char * start = memblock; int i = 0; char c; list<Frame> lst; ........... } // to the below one. list<Frame> FrameVisitor::get_frames(const char* myfilePath) { fstream myfile(myfilePath, ios::in); char * memblock = new char [4]; //1º 4 bytes da frame...header. char * start = memblock; int i = 0; char c; list<Frame> lst; ........... }
Try to pass the filePath not the streams between functions
just open the stream where required and close it after using.
as far as the problem is concerned there is no copy constructor defined for streams, whenever pass by value they'll cause problems.
check your code of class frame as well. rather than storing the stream as a member keep the file path as a member.
Hope this helps.
![]() |
Similar Threads
- singleton pattern and its destructor... (C++)
- cannot access private member declared in class (C++)
- Virtual Inheritance Question (C++)
- is not a class or namespace name error (C++)
- Get errors by using "friend function" (C++)
- can someone explain about this error (C++)
- Parent / child class problems (C++)
- Overloading << & >> operators (C++)
- Please I Need U Again (C++)
- C++ Tic Tac Toe using classes & operator overloading (C++)
Other Threads in the C++ Forum
- Previous Thread: Why wont my program read the last record in my data file?
- Next Thread: Almost got a working server. Two small problems.
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






