Static float array in header file

This is a discussion on Static float array in header file within the C++ Programming forums, part of the General Programming Boards category; I'm trying to declare and initialize several float arrays with Code: #pragma once class GlobalLight { private: static const GLfloat ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    101

    Question Static float array in header file

    I'm trying to declare and initialize several float arrays with

    Code:
    #pragma once
    
    class GlobalLight {
    private:
    	static const GLfloat FULLSUN[];
    };
    
    const GLfloat GlobalLight::FULLSUN[] = {240, 240, 188, 1};
    I get

    Code:
    1>GlobalLight.obj : error LNK2005: "private: static float const * const GlobalLight::FULLSUN" (?FULLSUN@GlobalLight@@0QBMB) already defined in CarRace.obj

    I've searched the web but found nothing Anyone knows how to do this?
    Last edited by kotoko; 06-15-2009 at 11:41 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,772
    Post the smallest and simplest program that demonstrates the error.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Student legit's Avatar
    Join Date
    Aug 2008
    Location
    UK -> Newcastle
    Posts
    156
    They are floats? Maybe they can't handle integers..... Just a thought, don't take my word for it, I don't do OpenGL

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    101
    The error was wrong I put it right now.

    I simplified the code as well.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,772
    Ah, just a moment: did you actually put this line in the header?
    Code:
    const GLfloat GlobalLight::FULLSUN[] = {240, 240, 188, 1};
    it belongs in exactly one source file.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    101
    That did the trick!

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  2. Problems in reading binary file
    By serena in forum C Programming
    Replies: 3
    Last Post: 04-14-2005, 03:54 AM
  3. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. ~ Array Help ~
    By Halo in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 03:19 PM

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