Can Anyone Explain this Error? (OpenGL)

This is a discussion on Can Anyone Explain this Error? (OpenGL) within the Game Programming forums, part of the General Programming Boards category; Heres the Code Renderer.h Code: #include <vector> #include "Vector3.h" using namespace std; struct BasicTri { Vector3 P1, P2, P3; int ...

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964

    Can Anyone Explain this Error? (OpenGL)

    Heres the Code


    Renderer.h
    Code:
    #include <vector>
    #include "Vector3.h"
    
    using namespace std;
    
    struct	BasicTri
    {
    	Vector3 P1, P2, P3;
    	int	Texture;
    
    
    	BasicTri(const BasicTri& t)
    	{
    		P1 = t.P1;
    		P2 = t.P2;
    		P3 = t.P3;
    		Texture = t.Texture;
    	}
    
    	BasicTri& operator=(const BasicTri& t)
    	{
    		if( &t != this ){
    			P1 = t.P1;
    			P2 = t.P2;
    			P3 = t.P3;
    			Texture = t.Texture;
    		}
    		return *this;
    	}
    };
    
    std::vector<BasicTri*>	mBasicTri;
    
    class GLRenderer
    {
    public:
    
    	void	AddBasicTriToRenderer(BasicTri* t)
    	{
    
    		// then add to the vector
    		mBasicTri.push_back(t);
    	}
    
    	void	RenderBasicTriangles(void);
    
    };
    And Renderer.cpp

    Code:
    #include "Renderer.h"
    And this is the error:

    Code:
    --------------------Configuration: NeHeGL - Win32 Debug--------------------
    Compiling...
    Renderer.cpp
    Example.cpp
    Linking...
    Renderer.obj : error LNK2005: "class std::vector<struct BasicTri *,class std::allocator<struct BasicTri *> > mBasicTri" (?mBasicTri@@3V?$vector@PAUBasicTri@@V?$allocator@PAUBasicTri@@@std@@@std@@A) already defined in Example.obj
    Debug/NeHeGL.exe : fatal error LNK1169: one or more multiply defined symbols found
    Error executing link.exe.
    
    NeHeGL.exe - 2 error(s), 0 warning(s)
    I've been working at this for hours, even rebuilt program from scratch, what is it?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Are you including Renderer.h in another file?

    You've defined a global in Renderer.h

    Code:
    std::vector<BasicTri*>	mBasicTri;
    and if you include Renderer.h in more than one source files (.cpp), you'll get a multiple definition error.

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Fixed

    made it extern in the header

    Declared it in the CPP
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 08-23-2008, 02:16 PM
  2. Please Explain me few terms that i have listed in here.
    By chottachatri in forum C++ Programming
    Replies: 3
    Last Post: 02-26-2008, 08:20 AM
  3. Can someone explain to me what this code means
    By Shadow12345 in forum C++ Programming
    Replies: 3
    Last Post: 12-22-2002, 12:36 PM
  4. explain this loop statement?
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 05-05-2002, 03:46 AM
  5. Can someone explain "extern" to me?
    By valar_king in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2001, 01:22 AM

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