I create the object Inicia in main function and have there a vector<frete> fretes and I want to store there frete objects but they are created in another function.
when compiling I get the error that i is a undeclared identifier... can anyone help
I have the following method in class inicia to add objects:
and in another class I have this method to receive the values and create the object:
void Funcionario::registo_frete(){
int continuar;
fstream ficheiro( "fretes.txt", ios::app );
if( !ficheiro)
{
cerr << endl;
cerr << "Erro ao abrir o ficheiro!" << endl;
exit( 1 );
}
do
{
cout << "Registo de Frete" << endl << endl;
string origem_temp = Interface::ler_string( "Introduza a origem: " );
string destino_temp = Interface::ler_string( "Introduza o destino: " );
string cliente_temp = Interface::ler_string( "Introduza o cliente: " );
int kms_temp = Interface::ler_int( "Introduza o numero de KM's: " );
int consumo_temp = Interface::ler_int( "Introduza o consumo de combustivel: " );
int portagens_temp = Interface::ler_int( "Introduza o valor de portagens: " );
int num_veiculo_temp = Interface::ler_int( "Introduza o numero do veiculo: " );
int preco_temp = Interface::ler_int( "Introduza o preco do frete: " );
cout << endl << endl;
Well, the compiler is telling you that i is an undeclared identifier because nowhere in your code do you instantiate a variable named "i" yet you try to reference one by that name in the line
If this 'i' is declared in main you can't access it with other functions, but you can pass a pointer to it to the function that needs access to it. You could also declare it globally, but that is considered bad practice.