Vectors within Structures

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joraara
    New Member
    • Sep 2007
    • 3

    Vectors within Structures

    Hi,

    I appreciate if someone is able to help me.

    I've declared a structure and two of it's members are vectors, let's say:

    #include <vector>
    using namespace std;
    struct str{
    vector< int >v1();
    vector< int >v2();
    } str;

    However, I don't manage to use those vectors as usual, for example: str.v1[i]=n or str.v2.resize(j ).

    Is there any way to handle them throughout the program?

    Any help would be wellcome. Thanks.
  • ilikepython
    Recognized Expert Contributor
    • Feb 2007
    • 844

    #2
    Originally posted by joraara
    Hi,

    I appreciate if someone is able to help me.

    I've declared a structure and two of it's members are vectors, let's say:

    #include <vector>
    using namespace std;
    struct str{
    vector< int >v1();
    vector< int >v2();
    } str;

    However, I don't manage to use those vectors as usual, for example: str.v1[i]=n or str.v2.resize(j ).

    Is there any way to handle them throughout the program?

    Any help would be wellcome. Thanks.
    Remove the parenthesis from the vector declarations and it should work. Whenever you want to declare an object with no arguments, leave off the parenthesis. Otherwise, the compiler thinks you are declaring a function.

    Comment

    • joraara
      New Member
      • Sep 2007
      • 3

      #3
      Originally posted by ilikepython
      Remove the parenthesis from the vector declarations and it should work. Whenever you want to declare an object with no arguments, leave off the parenthesis. Otherwise, the compiler thinks you are declaring a function.
      Thanks ilikepython for your reply.
      I've just done what you said and the compiler detedcs no error.
      Now the problem is trying to build the .obj; it's showing 3 errors and I have no idea what they mean. Here is the message:

      Linking...
      Facturacion.obj : error LNK2001: unresolved external symbol "struct product * producto" (?producto@@3PA Uproduct@@A)
      Facturacion.obj : error LNK2001: unresolved external symbol "struct factur * factura" (?factura@@3PAU factur@@A)
      Debug/Facturacion.exe : fatal error LNK1120: 2 unresolved externals
      Error executing link.exe.

      What should I review?
      Thanks.

      Comment

      • ilikepython
        Recognized Expert Contributor
        • Feb 2007
        • 844

        #4
        Originally posted by joraara
        Thanks ilikepython for your reply.
        I've just done what you said and the compiler detedcs no error.
        Now the problem is trying to build the .obj; it's showing 3 errors and I have no idea what they mean. Here is the message:

        Linking...
        Facturacion.obj : error LNK2001: unresolved external symbol "struct product * producto" (?producto@@3PA Uproduct@@A)
        Facturacion.obj : error LNK2001: unresolved external symbol "struct factur * factura" (?factura@@3PAU factur@@A)
        Debug/Facturacion.exe : fatal error LNK1120: 2 unresolved externals
        Error executing link.exe.

        What should I review?
        Thanks.
        That probably means the compiler can't find the definition of something. Can you post the Facturacion.cpp code?

        Comment

        Working...