Hello,
I am kind of stuck in a simple problem with vector of struct. I have used this many times before without any problem but suddenly some issues are now cropping up!
//test.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#ifndef __TEST_H
#define __TEST_H
#include <vector>
class test{
struct A {
int a;
int b;
};
public:
vector<A*> table;
test();
A* getRowFromTable(int index) const;
};
#endif
|
//test.C
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include "test.h"
test::test() {
for(int i=0; i<2; i++) {
A* mem = new A;
mem->a = i+10;
mem->b = i*10;
table.push_back(mem);
}
}
A* test::getRowFromTable(int index) const {
return table[index];
}
|
The code does not compile and I could not find a reason since I have used this type of data structures before successfully.
The error messages are:
user@localhost 200% g++ -Wall -c -O3 test.C
In file included from test.C:1:
test.h:14: error: ISO C++ forbids declaration of ‘vector’ with no type
test.h:14: error: expected ‘;’ before ‘<’ token
test.C: In constructor ‘test::test()’:
test.C:8: error: ‘table’ was not declared in this scope
test.C: At global scope:
test.C:12: error: expected constructor, destructor, or type conversion before ‘*’ token
user@localhost 201%
Why does it not able to recognize the declared struct!
Any help will be highly appreciated!
Thanks!