Static structure

This is a discussion on Static structure within the C++ Programming forums, part of the General Programming Boards category; Hello everyone, I'm trying to accomplish a static structure but fail miserably. If I define them non static everything works ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    2

    Static structure

    Hello everyone,

    I'm trying to accomplish a static structure but fail miserably. If I define them non static everything works as it should, but trying to define it static fails by all google-solutions. Therefore my post here!

    My Code:
    structure in Genre.h
    Code:
    struct genre{
    	int id;
    	string name;
    	int score;
    };
    Code:
    class iDNA {
    	private:
    		static genre _go_genre[1750];
    Code:
    void iDNA::loadDefaults() {
    [...]
    		while (res->next()) {
    			_go_genre[li_count].name = res->getString("name");
    			li_count++;
    		}
    Error:
    iDNA.o: In function `iDNA::loadDefaults()':
    iDNA.cpp: (.text+0x319): undefined reference to `iDNA::_go_genre'
    collect2: ld returned 1 exit status
    make: *** [iDNA] Error 1
    OS: Arch Linux x86
    Compiler: gcc version 4.4.2 (GCC)
    Linker: GNU ld (GNU Binutils) 2.20.0.20091101

    Hopefully I provided enough information. If not just ask for more!


    Thanks in advance,

    Arjan Gelderblom

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,744
    You probably forgot to define the array. In a source file, write:
    Code:
    genre iDNA::_go_genre[1750];
    By the way, avoid using names that begin with underscores since they may be reserved to the compiler and standard library implementation. In this case because the underscore is followed by a lowercase letter, and the name is at class scope, it is okay, but still
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    2
    Wow, lightning fast answer! And i

    Quote Originally Posted by laserlight View Post
    You probably forgot to define the array. In a source file, write:
    Code:
    genre iDNA::_go_genre[1750];
    Isn't this done by the first part of the code with:
    Code:
    class iDNA {
    	private:
    		static genre _go_genre[1750];
    Quote Originally Posted by laserlight View Post
    By the way, avoid using names that begin with underscores since they may be reserved to the compiler and standard library implementation. In this case because the underscore is followed by a lowercase letter, and the name is at class scope, it is okay, but still
    Thanks for pointing this out... Will change this right away!

    Thanks, Bloged

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,744
    Quote Originally Posted by Bloged
    Isn't this done by the first part of the code with:
    No, that is just a declaration.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  2. uploading file to http server via multipart form data
    By Dynamo in forum C++ Programming
    Replies: 1
    Last Post: 09-03-2008, 04:36 AM
  3. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  4. static data members in structure
    By bhagwat_maimt in forum C++ Programming
    Replies: 9
    Last Post: 11-06-2006, 10:47 AM
  5. program to unpack packed data
    By vsk in forum C Programming
    Replies: 5
    Last Post: 11-14-2002, 08:17 PM

Tags for this Thread


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