Sou iniciante na programação em C++ e me deparei com um problema quando tentava executar meu código no atom, usando o pacote gpp-compiler e o MinGW: 'function' was not declared in this scope (l.8). Não entendi o motivo do erro, alguém pode me ajudar?
Aqui está a função main:
#include <iostream>
#include "header.hpp"
using namespace std;
int main(){
int* a;
a = function(50);
for(int d = 0; d < a.length; d++){
.
.
.
}
system("pause");
return 0;
}
e o arquivo header:
#ifndef FUNCTIONS_H_INCLUDED
#define FUNCTIONS_H_INCLUDED
#include <vector>
int* function(int num){
std::vector<int> c;
.
.
.
int z[(int)c.size()];
for(int b = 0; b < (int)c.size(); b++){
z[b] = c.at(b);
}
return z;
}
#endif
Pra ser mais específico, a mensagem de erro foi assim:
...\main.cpp: In function 'int main()':
...\main.cpp:9:18: error: 'function' was not declared in this scope
a = function(50);...\main.cpp:10:23: error: request for member 'length' in 'a', which is of non-class type 'int*' for(int d = 0; d < a.length; d++){
int*
não pode fazer.length
. Apesar desses dois erros experimentei compilar o seu código e não obtive o erro que indica. Como está a fazer a compilação ? a mão (se sim como?) ou num IDE ? (se sim qual ?)