beginner question on vector<struct>

Discussion in 'C++' started by ali labed, Dec 6, 2005.

  1. ali labed

    ali labed Guest

    Does MS Visual C++ not accept vector of a structure ? (in acceptes
    vector<int>)

    struct str1
    {
    string name;
    int num;
    };

    vector<str1> vec_str( 10 ); // <== rejected

    Thanks.
     
    ali labed, Dec 6, 2005
    #1
    1. Advertising

  2. ali labed wrote:
    > Does MS Visual C++ not accept vector of a structure ? (in acceptes
    > vector<int>)
    >
    > struct str1
    > {
    > string name;
    > int num;
    > };
    >
    > vector<str1> vec_str( 10 ); // <== rejected


    FAQ 5.8
     
    Victor Bazarov, Dec 7, 2005
    #2
    1. Advertising

  3. ali labed

    Guest

    ali labed wrote:

    > Does MS Visual C++ not accept vector of a structure ? (in acceptes
    > vector<int>)
    >
    > struct str1
    > {
    > string name;
    > int num;
    > };
    >
    > vector<str1> vec_str( 10 ); // <== rejected


    Which version of Visual C++? What is the error message?

    I put this

    #include <string>
    #include <vector>
    using namespace std;

    above your code and Visual C++ 8 Express compiled it, as did Comeau
    online.

    Gavin Deane
     
    , Dec 7, 2005
    #3
  4. ali labed

    Axter Guest

    ali labed wrote:
    > Does MS Visual C++ not accept vector of a structure ? (in acceptes
    > vector<int>)
    >
    > struct str1
    > {
    > string name;
    > int num;
    > };
    >
    > vector<str1> vec_str( 10 ); // <== rejected
    >
    > Thanks.


    Are you sure you posted the full code?
    If your struct has an explict constructor, but no default constructor,
    then the above would not compile.
    But your above example as is should compile. Please post exact compile
    error you're getting.
     
    Axter, Dec 7, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pmatos
    Replies:
    6
    Views:
    23,855
  2. Chris Fogelklou
    Replies:
    36
    Views:
    1,393
    Chris Fogelklou
    Apr 20, 2004
  3. Mark McIntyre

    C beginner: struct inside another struct...

    Mark McIntyre, Apr 21, 2006, in forum: C Programming
    Replies:
    5
    Views:
    671
    Yourko
    Apr 23, 2006
  4. Replies:
    8
    Views:
    1,939
    Csaba
    Feb 18, 2006
  5. Javier
    Replies:
    2
    Views:
    574
    James Kanze
    Sep 4, 2007
Loading...

Share This Page