using extern, please help

This is a discussion on using extern, please help within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm trying to use extern for a struct. The struct is for vertices and is first used in a ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    23

    using extern, please help

    Hi, I'm trying to use extern for a struct.

    The struct is for vertices and is first used in a vertex class

    Code:
    ///////////////////////////////////////////
    //file vertices.h
    ///////////////////////////////////////////
    struct vertex{
    float x, y, z;
    };
    
    class VertexClass
    {
    vertex *vert; 
    ...
    void MakeVertices(int howmany);//make vertices
    };
    
    
    
    
    ///////////////////////////////////////////
    //file vertexData.h
    ///////////////////////////////////////////
    
    //trying to use extern of above vertex struct
    extern vertex *DataForVertex;
    
    class VData
    {
    vertex *DataForVertex;
    ...
    ...
    //I'm trying to pass one of the vertice structs from the other 
    //class into this 
    
    void MakeVertex()//initialise the external vertex 
    void GetVertexData(vertex *data)//get data from the vertices in above class
    
    
    };
    Basicly I'm making vertex objects in the first class and in the second class I want to pass those objects (in a loop), to do calculations on them. I think if I'm trying to pass a pointer to a whole vertex instance at once , then I also need the same type to "recieve" the data? What I'm actrually trying to pass is a VertexClass->vertex[n].

    I have tried this but I get an undefined variable error for the vertex struct.

    Can any one help me with this?
    Thanks
    Last edited by Stevo; 10-10-2004 at 05:52 PM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,254
    You need to declare the variable in a .cpp file as well without the "extern" keyword.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    23
    Thanks for the replay, I just tried that but I'm getting a "no apprpriate constructor available" error.

    I have used extern before but I can't find the project I used it in now.
    The problem might be in how I'm trying to use it, are you allowed to use extern for a pointer?

    I just thought, does extern have to refer to an already instantiated object, or is it just telling the compiler that the definition is somewhere else?
    Last edited by Stevo; 10-10-2004 at 07:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. extern classes
    By Swordsman in forum C++ Programming
    Replies: 1
    Last Post: 05-07-2008, 03:07 AM
  2. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  3. Odd Problem with Linking
    By jamez05 in forum C++ Programming
    Replies: 6
    Last Post: 09-21-2005, 02:49 PM
  4. Extern Question, really confused
    By SourceCode in forum C Programming
    Replies: 10
    Last Post: 03-26-2003, 11:11 PM
  5. extern symbols, what do these mean exactly?
    By Shadow12345 in forum C++ Programming
    Replies: 8
    Last Post: 11-02-2002, 03:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21