943,594 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1107
  • C++ RSS
Aug 11th, 2009
0

Error C2248 - Clueless

Expand Post »
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 :

C++ Syntax (Toggle Plain Text)
  1.  
  2. #endif
  3.  
  4. #ifndef VISITOR_H
  5. #define VISITOR_H
  6.  
  7. #include <stdio.h>
  8. #include <sstream>
  9. #include <fstream>
  10. #include <list>
  11.  
  12. using namespace std;
  13.  
  14. class FrameVisitor : public Frame
  15. {
  16. list<Frame> frames;
  17.  
  18. public:
  19.  
  20. FrameVisitor();
  21. list<Frame> get_frames(fstream& file);
  22. bool getFirstFrame(Frame& f);
  23. void WriteFrame(Frame f, FILE * dst);
  24. int fastValidation(Frame f);
  25.  
  26. };
  27.  
  28. #endif

implementation:

C++ Syntax (Toggle Plain Text)
  1.  
  2. #include "Mp3.h"
  3.  
  4. using namespace std;
  5.  
  6. FrameVisitor::FrameVisitor()
  7. {
  8. Frame();
  9. frames = get_frames(myfile);
  10. }
  11.  
  12. void FrameVisitor::WriteFrame(Frame f, FILE * dst)
  13. {
  14. size_t num_bytes = f.getLength(); //size_t size var de instancia de Frame.
  15. memcpy(dst,f.frame,num_bytes);
  16.  
  17. //Duvida: É preciso criar um novo file com o mm nome, escrever la a frame e depois o resto?
  18. //ou basta escrever por cima como tou a fazer aqui?
  19.  
  20. }
  21.  
  22. list<Frame> FrameVisitor::get_frames(fstream& myfile)
  23. {
  24.  
  25. char * memblock = new char [4]; //1º 4 bytes da frame...header.
  26. char * start = memblock;
  27. int i = 0;
  28. char c;
  29. list<Frame> lst;
  30. Frame f;
  31.  
  32. while(!myfile.eof()){
  33.  
  34. while(i<4){
  35.  
  36. c=myfile.get();
  37. f.addByte(c);
  38. memblock[i++]=c;
  39.  
  40. }
  41. myfile.seekg(-4,ios::cur);
  42. i = 0;
  43.  
  44. if((memblock[0] == 0xFF) && ((memblock[1])& 0xE0) == 0xE0)
  45. {
  46. f.getFrame(myfile);//Pedaço do ficheiro ate encontrar prox header.
  47.  
  48. //Construir uma frame para meter na lista.
  49. if(fastValidation(f) == 0)
  50. {
  51.  
  52. lst.push_back((f));
  53. memblock = start;
  54. }
  55. else
  56. {
  57. f.clear();
  58. memblock = start;
  59. myfile.seekg(1,ios::cur);
  60. }
  61. }
  62. myfile.seekg(1,ios::cur);
  63. memblock = start;
  64. f.clear();
  65. }
  66. return lst;
  67. }
  68.  
  69. int FrameVisitor::fastValidation(Frame f)
  70. {
  71.  
  72. if((f.getVersion() ==1) || (f.getLayer() == 0) || (f.getBitrate() == 0 || f.getBitrate() == 15) || (f.getFrequency() == 3))
  73. return -1;
  74. return 0;
  75.  
  76. }
  77.  
  78. bool FrameVisitor::getFirstFrame(Frame& f)
  79. {
  80. if(!frames.empty())
  81. {
  82. f = frames.front();
  83. return true;
  84. }
  85. return false;
  86. }

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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Nogat21 is offline Offline
60 posts
since Jul 2009
Aug 11th, 2009
1

Re: Error C2248 - Clueless

which line does it point to?
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,862 posts
since Dec 2008
Aug 11th, 2009
0

Re: Error C2248 - Clueless

It points directly to fstream. It doesnt indicate in which line of my code the error occurs
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Nogat21 is offline Offline
60 posts
since Jul 2009
Aug 11th, 2009
0

Re: Error C2248 - Clueless

I've few questions,

C++ Syntax (Toggle Plain Text)
  1. FrameVisitor::FrameVisitor()
  2. {
  3. Frame();
  4. frames = get_frames(myfile);
  5. }
you have passed 'myfile' as a parameter in fstream where it is defined?

change the following Code.
C++ Syntax (Toggle Plain Text)
  1. list<Frame> FrameVisitor::get_frames(fstream& myfile)
  2. {
  3.  
  4. char * memblock = new char [4]; //1º 4 bytes da frame...header.
  5. char * start = memblock;
  6. int i = 0;
  7. char c;
  8. list<Frame> lst;
  9. ...........
  10. }
  11.  
  12. // to the below one.
  13. list<Frame> FrameVisitor::get_frames(const char* myfilePath)
  14. {
  15. fstream myfile(myfilePath, ios::in);
  16. char * memblock = new char [4]; //1º 4 bytes da frame...header.
  17. char * start = memblock;
  18. int i = 0;
  19. char c;
  20. list<Frame> lst;
  21. ...........
  22.  
  23. }

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.
Reputation Points: 113
Solved Threads: 20
Junior Poster
Laiq Ahmed is offline Offline
147 posts
since Jun 2006
Aug 11th, 2009
0

Re: Error C2248 - Clueless

Last edited by firstPerson; Aug 11th, 2009 at 12:01 pm.
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,862 posts
since Dec 2008
Aug 11th, 2009
0

Re: Error C2248 - Clueless

Yeah its a good way of avoiding this problem...i'm not very happy with this implementation, im going to start this from scratch. Thanks for your help.

If i have some more doubts and problems i'll open another post.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Nogat21 is offline Offline
60 posts
since Jul 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Why wont my program read the last record in my data file?
Next Thread in C++ Forum Timeline: Almost got a working server. Two small problems.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC