Hi, i'm doing a project in Visual C++....in Portuguese....i'm hoping you can help figure out the problem eventhough it's not in english...

here is the whole code....incomplete in the int main and it's missing some functions but i wanted to solve this errors before i keep going

CNoFila.h:

include <iostream>


class CNoFila{
  public:
	int evento;
	int tempo;
	CNoFila *Proximo;
};



class CFilaLavagem{
	CNoFila *InicioLav;
    CNoFila *FimLav;
  public:
	CFilaLavagem(void);                      //constructor por defeito
	~CFilaLavagem(void);                 //Destructor

	void ApagaItemLav(int);
	int lugareslavagem(void);
	friend void spot(int n1, CNoFila &Carro, int tempo, int evento);
	void EstacParaLavagem(const CNoFila &L);
	void InsereItemLav(int evento, int tempo);
};


class CFilaEstacionamento{
	CNoFila *InicioEstac;
    CNoFila *FimEstac;
  public:
	CFilaEstacionamento();                      //constructor por defeito
	CFilaEstacionamento(const CNoFila & L);
	~CFilaEstacionamento(void);                 //Destructor

	void ApagaItemEstac(int);
	int lugaresestacionamento(void);
	friend void spot(int n1, CNoFila &Carro, int tempo, int evento);
	
	void InsereItemEstac(int evento, int tempo);
};

CFilaLavagem.cpp

#include "CNoFila.h"

CFilaLavagem::CFilaLavagem(void)
{

	InicioLav = FimLav = NULL;

}

CFilaLavagem::~CFilaLavagem(void)
{

	delete this;

}


int CFilaLavagem::lugareslavagem(void)
{
	int lavagem = 0;
	CNoFila *Actual = InicioLav;
	
	if (Actual==NULL) return 0;
	else{
		while(Actual!=NULL)
		{
			lavagem++;
			Actual = Actual->Proximo;
		}
	}
	return (lavagem);

}




void CFilaLavagem::EstacParaLavagem(const CNoFila &L)
{

	CNoFila *Novo = new CNoFila;
	
	Novo->evento = L.evento;
	Novo->tempo = L.tempo;
	Novo->Proximo=NULL;
	if( InicioLav == NULL ) InicioLav = Novo;  
	else{
		FimLav->Proximo = Novo; 
	}
	
	FimLav = Novo;
}

void CFilaLavagem::InsereItemLav(int evento, int tempo)
{

	CNoFila *Novo = new CNoFila;
	
	Novo->evento =evento;
	Novo->tempo = tempo;
	Novo->Proximo=NULL;
	if( InicioLav == NULL ) InicioLav = Novo;  
	else{
		FimLav->Proximo = Novo; 
	}
	
	FimLav = Novo;
}

CFilaEstacionamento:

#include "CNoFila.h"


CFilaEstacionamento::~CFilaEstacionamento()
{

	delete this;

}

CFilaEstacionamento::CFilaEstacionamento()
{

	InicioEstac = FimEstac = NULL;

}

int CFilaEstacionamento::lugaresestacionamento(void)
{
	int estac = 0;
	CNoFila *Actual = InicioEstac;
	
	if (Actual==NULL) return 0;
	else{
		while(Actual!=NULL)
		{
			estac++;
			Actual = Actual->Proximo;
		}
	}
	return (estac);
}



void CFilaEstacionamento::InsereItemEstac(int evento, int tempo) {
	
	CNoFila *Novo = new CNoFila;
	
	Novo->evento = evento;
	Novo->tempo = tempo;
	Novo->Proximo=NULL;
	if( InicioEstac == NULL ) InicioEstac = Novo;  
	else{
		FimEstac->Proximo = Novo; 
	}
	
	FimEstac = Novo;
}

main.cpp:

#include <iostream>
#include "CNoFila.h"
#include "time.h"
#include <fstream>

using namespace std;



void spot(int n1, CNoFila Carro, int tempo, int evento, int &carrosout)
{
	
	int lugaresestac= 2 * (8-n1);
	int lavagemocupado = lugareslavagem();
	int estacocupado = lugaresestacionamento();

	if (lavagemocupado < n1){
		if (estacocupado ==0){
			InsereItemLav(evento, tempo);
		}

		else {
			EstacParaLavagem(Carro);
			InsereItemEstac(evento, tempo);
		}
	}

	if (lavagemocupado == n1){
		if (estacocupado < lugaresestac){
			InsereItemEstac(evento, tempo);
		}
		
		else{
			carrosout++;
		}




	}

}


void Imprime(int numerocarro, int numlugar, int situacao, clock_t tempo){

	
	ofstream fout;
	
	fout.open("Registo.txt");
	
	switch (situacao){
	case 0: fout << tempo << " - Chegada de um novo cliente (#" << numerocarro << "). Ocupa o lugar de lavagem #" << numlugar << ". Executa a opcao escolhida." << endl; 
	break;
	case 1: fout << tempo << " - Chegada de um novo cliente (#" << numerocarro << "). Ocupa o lugar de estacionamento #" << numlugar << ". Aguarda a sua vez." << endl;
	break;
	case 2: fout << tempo << " - Chegada de um novo cliente (#" << numerocarro << "). Os lugares estao todos ocupados e o carro vai-se embora" << endl;
	break;
	case 3: fout << tempo << " - O cliente #" << numerocarro << " que se encontrava no estacionamento desloca-se para o lugar de lavagem #" << numlugar << endl; 
	}

	fout.close();
	
}
int main()
{
	

	int n1;

	do{
	cout << "Introduza o numero de zonas de lavagem a simular(1 a 8): ";
	cin >> n1;
	}while(1 > n1 && n1 > 8);

	cout << "\nO numero total de lugares de estacionamento e': " << 2 * (8-n1) << endl;

	return 0;
}

this are the errors:

1>main.cpp
1>c:\users\tiago\documents\visual studio 2008\projects\projectoeda\projectoeda\main.cpp(14) : error C3861: 'lugareslavagem': identifier not found
1>c:\users\tiago\documents\visual studio 2008\projects\projectoeda\projectoeda\main.cpp(15) : error C3861: 'lugaresestacionamento': identifier not found
1>c:\users\tiago\documents\visual studio 2008\projects\projectoeda\projectoeda\main.cpp(19) : error C3861: 'InsereItemLav': identifier not found
1>c:\users\tiago\documents\visual studio 2008\projects\projectoeda\projectoeda\main.cpp(23) : error C3861: 'EstacParaLavagem': identifier not found
1>c:\users\tiago\documents\visual studio 2008\projects\projectoeda\projectoeda\main.cpp(24) : error C3861: 'InsereItemEstac': identifier not found
1>c:\users\tiago\documents\visual studio 2008\projects\projectoeda\projectoeda\main.cpp(30) : error C3861: 'InsereItemEstac': identifier not found
thanks for any help

Recommended Answers

All 6 Replies

Hello,

All these identifiers not found and listed in error listing are class functions, e.g. lugareslavagem in line 21. They are declared in CNoFila.h, however, there exists no implementation as yet.

Corresponding to include file CNoFila.h there usually exists a further implemention file CNoFila.cpp, or some such thing, which must be included too. Furthermore, this implemention file must be part of your project or in the makefile depending on your developing system, e.g. visual studio, kdevelop, wxDec-c++ etc.

-- tesu

Well you're right, i forgot that, because i first had de 3 classes in 3 different files but i wrote them all in CNoFila.h and left the functions of the classes CFilaEstacionamento and CFilaLavagem in the wrong files...

So i did what you said and copied the class functions to CNoFila.cpp and deleted CFilaEstacionamento.cpp and also CFilaLavagem.cpp

unfortunately it didn't solve the problem and the same 6 errors remain.. :(

CNoFila.cpp

#include "CNoFila.h"

//CFilaLavagem
CFilaLavagem::CFilaLavagem(void)
{

	InicioLav = FimLav = NULL;

}

CFilaLavagem::~CFilaLavagem(void)
{

	delete this;

}


int CFilaLavagem::lugareslavagem(void)
{
	int lavagem = 0;
	CNoFila *Actual = InicioLav;
	
	if (Actual==NULL) return 0;
	else{
		while(Actual!=NULL)
		{
			lavagem++;
			Actual = Actual->Proximo;
		}
	}
	return (lavagem);

}




void CFilaLavagem::EstacParaLavagem(const CNoFila &L)
{

	CNoFila *Novo = new CNoFila;
	
	Novo->evento = L.evento;
	Novo->tempo = L.tempo;
	Novo->Proximo=NULL;
	if( InicioLav == NULL ) InicioLav = Novo;  
	else{
		FimLav->Proximo = Novo; 
	}
	
	FimLav = Novo;
}

void CFilaLavagem::InsereItemLav(int evento, int tempo)
{

	CNoFila *Novo = new CNoFila;
	
	Novo->evento =evento;
	Novo->tempo = tempo;
	Novo->Proximo=NULL;
	if( InicioLav == NULL ) InicioLav = Novo;  
	else{
		FimLav->Proximo = Novo; 
	}
	
	FimLav = Novo;
}

//CFilaEstacionamento

CFilaEstacionamento::~CFilaEstacionamento()
{

	delete this;

}

CFilaEstacionamento::CFilaEstacionamento()
{

	InicioEstac = FimEstac = NULL;

}

int CFilaEstacionamento::lugaresestacionamento(void)
{
	int estac = 0;
	CNoFila *Actual = InicioEstac;
	
	if (Actual==NULL) return 0;
	else{
		while(Actual!=NULL)
		{
			estac++;
			Actual = Actual->Proximo;
		}
	}
	return (estac);
}



void CFilaEstacionamento::InsereItemEstac(int evento, int tempo) {
	
	CNoFila *Novo = new CNoFila;
	
	Novo->evento = evento;
	Novo->tempo = tempo;
	Novo->Proximo=NULL;
	if( InicioEstac == NULL ) InicioEstac = Novo;  
	else{
		FimEstac->Proximo = Novo; 
	}
	
	FimEstac = Novo;
}

Hi

Did you #include "CNoFila.cpp" in your main() file ?

Did you add CNoFila.cpp to your project file or make ?

Which system do you use for programming, visual studio 2010?

-- tesu

I'm using visual studio 2008, the CNoFila.cpp is in the source files, but i didn't #include "CNoFila.cpp" in the main file...but usually when i work with this type of file hierarchy including the header file CNoFila.h it isn't necessary to include CNofila.cpp and it worked fine in other projects...

ps:including CNoFila.cpp in the main file brings more errors...such as:
error C2011: 'CNoFila' : 'class' type redefinition
error C2011: 'CFilaLavagem' : 'class' type redefinition
error C2011: 'CFilaEstacionamento' : 'class' type redefinition

and it brings many errors like using indefined type 'class' (class being the name of the three classes)

There was nothing wrong with your original implementation except one thing.

You had not made an instantiation of the class. You cannot access the methods of a class, without first making a copy of the class itself.

In your main.cpp file, you need a line somewhere that would read CFilaLavagem myClass; Then you can use your methods as such: myClass.InsereItemLav(1,2)

with the main.cpp file like this:

#include <iostream>
#include "CNoFila.h"
#include "time.h"
#include <fstream>
CFilaLavagem myClass;
CFilaEstacionamento myClass1;

using namespace std;



int spot(int n1, CNoFila Carro, int tempo, int evento, int &carrosout)
{
	int situacao;

	int lugaresestac= 2 * (8-n1);
	int lavagemocupado = myClass.lugareslavagem();
	int estacocupado = myClass1.lugaresestacionamento();

	if (lavagemocupado < n1){
		if (estacocupado ==0){
			myClass.InsereItemLav(evento, tempo);
			situacao = 0;
		}

		else {
			myClass.EstacParaLavagem(Carro);
			myClass1.InsereItemEstac(evento, tempo);
			situacao = 1;
		}
	}

	if (lavagemocupado == n1){
		if (estacocupado < lugaresestac){
			myClass1.InsereItemEstac(evento, tempo);
			situacao = 1;
		}
		
		else{
			carrosout++;
			situacao = 2;
		}




	}

	return (situacao);
}


void Imprime(int numerocarro, int numlugar, int situacao, clock_t tempo){

	
	ofstream fout;
	
	fout.open("Registo.txt");
	
	switch (situacao){
	case 0: fout << tempo << " - Chegada de um novo cliente (#" << numerocarro << "). Ocupa o lugar de lavagem #" << numlugar << ". Executa a opcao escolhida." << endl; 
	break;
	case 1: fout << tempo << " - Chegada de um novo cliente (#" << numerocarro << "). Ocupa o lugar de estacionamento #" << numlugar << ". Aguarda a sua vez." << endl;
	break;
	case 2: fout << tempo << " - Chegada de um novo cliente (#" << numerocarro << "). Os lugares estao todos ocupados e o carro vai-se embora" << endl;
	break;
	case 3: fout << tempo << " - O cliente #" << numerocarro << " que se encontrava no estacionamento desloca-se para o lugar de lavagem #" << numlugar << endl; 
	}

	fout.close();
	
}
int main()
{
	

	int n1;

	do{
	cout << "Introduza o numero de zonas de lavagem a simular(1 a 8): ";
	cin >> n1;
	}while(1 > n1 && n1 > 8);

	cout << "\nO numero total de lugares de estacionamento e': " << 2 * (8-n1) << endl;

	return 0;
}

the errors are gone!!!

thank you for your help!!! :)

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.