J
jczhang
Hi,
I have a question when using STL. Look at this piece of code:
1 #include <vector>
2
3 using namespace std;
4
5 int main() {
6 typedef struct student {
7 char* name;
8 int age;
9 } STUDENT;
10 typedef vector<STUDENT> STUDENT_VECTOR;
11 STUDENT_VECTOR students;
12 }
When I compile it using gcc3.2, the compiler complains:
tmp.cxx: In function `int main()':
tmp.cxx:10: template-argument `main()::STUDENT' uses local type `
main()::STUDENT'
tmp.cxx:10: template argument 2 is invalid
tmp.cxx:10: ISO C++ forbids declaration of `STUDENT_VECTOR' with no type
But if I move the typedef of STUDENT(line 6~9) out of function main, the error will disappear.
I wonder why.
Thank you!
-- jczhang
I have a question when using STL. Look at this piece of code:
1 #include <vector>
2
3 using namespace std;
4
5 int main() {
6 typedef struct student {
7 char* name;
8 int age;
9 } STUDENT;
10 typedef vector<STUDENT> STUDENT_VECTOR;
11 STUDENT_VECTOR students;
12 }
When I compile it using gcc3.2, the compiler complains:
tmp.cxx: In function `int main()':
tmp.cxx:10: template-argument `main()::STUDENT' uses local type `
main()::STUDENT'
tmp.cxx:10: template argument 2 is invalid
tmp.cxx:10: ISO C++ forbids declaration of `STUDENT_VECTOR' with no type
But if I move the typedef of STUDENT(line 6~9) out of function main, the error will disappear.
I wonder why.
Thank you!
-- jczhang