c++ - C language Function errors -
i use c language , need write program different function. have problems , didn't find solution.
i have 2 kind of function. one
int x(int i, int k){ int p, n; return p + (i-1)*(n-1) + (k-1); } in function, have following error: error c2601: 'x' : local function definitions illegal
the other 1
void mode(){ matrix_entry temp; temp=m[i]; m[i]=m[small_i]; m[small_i]=temp; the problem matrix_entry, temp , m undeclared identifier
can me find mistakes? thanks
error c2601: 'x' : local function definitions illegal
it sounds you're defining function inside function; c++ doesn't allow that. move definition of x outside function it's in.
another possibility there's function before x, , missed out } @ end of function.
the problem matrix_entry, temp , m undeclared identifier in main have this:
firstly, types need declared before they're used. sounds function appears either before definition of matrix_entry, or in different source file.
either move definition of matrix_entry point before needs use it, or put in header , include each source file needs it. fix first 2 "undeclared identifier" errors matrix_entry , temp.
if m in main, it's not available in other functions. pass function(s) need it:
void mode(matrix_entry * m){ matrix_entry temp; temp=m[i]; m[i]=m[small_i]; m[small_i]=temp; } int main() { matrix_entry *m = new matrix_entry [10]; //... mode(m); //... // don't forget delete new // (better still don't new in first place, // or use smart pointers if must) delete [] m; }
Comments
Post a Comment