Thread: using extern, please help

  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 04:52 PM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    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 06: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, 02: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, 01: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