A question about using struct in STL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jczhang

    A question about using struct in STL

    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()::STUDEN T' 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
  • Frank Schmitt

    #2
    Re: A question about using struct in STL

    "jczhang" <jczhang@ict.ac .cn> writes:

    *Please* don't post HTML to this group.

    regards
    frank

    --
    Frank Schmitt
    4SC AG phone: +49 89 700763-0
    e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com

    Comment

    Working...