using an array of structures in multiple .cpp files in VC++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • opendep
    New Member
    • Feb 2008
    • 4

    #1

    using an array of structures in multiple .cpp files in VC++

    hi,
    my project has a header file structure.h which has the following code

    [code=cpp]
    #ifndef STRUCTURE_H
    #define STRUCTURE_H
    #include <stdio.h>

    typedef struct
    {
    float x,y,z;

    }position_s ;

    typedef struct
    {
    float r,g,b,a;

    }color_s ;

    typedef struct
    {
    int size;
    bool blend;
    position_s pos;
    color_s colour;

    }point_s;

    extern point_s dp[];
    #endif
    [/code]

    I need to create a dynamic array of point_s structure objects ( the array may be as large as a million depending on the number of points present in a file).

    one .cpp file is used for reading a file( of specific format which gives x y z r g b values) and these values shud be stored in the structure objects ( objects in the array dp).

    this array shud be accessible to another .cpp file which displays the points on a 3D window.

    I have included structure.h in both the files but it gives a build error

    filehandling.ob j : error LNK2019: unresolved external symbol "struct point_s * dp" (?dp@@3PAUpoint _s@@A) referenced in function "void __cdecl fileopen2(void) " (?fileopen2@@YA XXZ)
    fatal error LNK1120: 1 unresolved externals

    Can anyone help me with this?

    thank you.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    The line

    extern point_s dp[];

    just declares a variable of type point_s * it does not define it. A declaration says something exists, where as a definition creates it. You have said dp exists but because you have not defined it it does not exist so you get unresolved external (it doesn't exist) errors.

    You need to put

    point_s *dp;

    in a cpp file somewhere.

    Comment

    Working...