1
I’m a beginner in C++ programming and came across a problem when trying to execute my code on Atom, using the gpp-Compiler package and Mingw: 'Function' was not declared in this Scope (l.8). I didn’t understand the reason for the error, someone can help me?
Here is the main function:
#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;
}
and the header file:
#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
To be more specific, the error message was like this:
...\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++){
If I didn’t miss anything by looking over, there’s probably another mistake that’s causing this.
– Maniero
Return a array place created in the function alone is already wrong, and on a
int*
can’t do.length
. Despite these two errors I tried to compile your code and did not get the error you indicate. How are you doing the compilation ? by hand (if yes how? ) or an IDE ? (if yes which ?)– Isac
Are you using Visual Studio? the #include "stdafx. h" is like the first include (or before your header)?
– Penachia
The question has been updated.
– VariablE