Thread: static member variable

  1. #1
    Registered User
    Join Date
    Feb 2010

    static member variable


    I have a static member variable "total" and I want to use it inside this class.
    Can somebody explain me why this doesn't work?

    #include "Artikel.h"
    class WinkelCar {
    		void add(int index, Artikel *object);
    		void ShowCar();
    		Artikel *array[2];
    		static int total;
    int WinkelCar::total = 0;
    If i compile this, I get this error:
    ld: duplicate symbol WinkelCar::total      in /var/folders/LO/LOQvxAvTExyhCT-wRaKGYU+++TI/-Tmp-//ccH9KXCA.o and /var/folders/LO/LOQvxAvTExyhCT-wRaKGYU+++TI/-Tmp-//ccObRT7c.o
    collect2: ld returned 1 exit status

    Thank you very much

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    It looks like you're #including your class.cpp file in multiple other source files.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2010
    ty that was the error

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [C#] Intercept SysListView32 item added
    By Devils Child in forum Windows Programming
    Replies: 9
    Last Post: 03-26-2010, 07:29 AM
  2. Problem defining structure
    By MTK in forum C Programming
    Replies: 12
    Last Post: 09-08-2009, 03:26 PM
  3. Problem with Free.
    By chakra in forum C Programming
    Replies: 9
    Last Post: 12-15-2008, 11:20 AM
  4. Replies: 2
    Last Post: 04-19-2008, 12:06 AM
  5. Replies: 3
    Last Post: 10-10-2002, 07:34 AM