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 :

#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:

#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 ==========

which line does it point to?

It points directly to fstream. It doesnt indicate in which line of my code the error occurs :S

I've few questions,

FrameVisitor::FrameVisitor()
{
	Frame();
	frames = get_frames(myfile);
}

you have passed 'myfile' as a parameter in fstream where it is defined?

change the following Code.

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.