static member variable

This is a discussion on static member variable within the C++ Programming forums, part of the General Programming Boards category; Hello I have a static member variable "total" and I want to use it inside this class. Can somebody explain ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    115

    static member variable

    Hello

    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?

    Code:
    #include "Artikel.h"
    
    class WinkelCar {
    
    
    	public:
    
    		void add(int index, Artikel *object);
    		void ShowCar();
    		
    	private:
    		Artikel *array[2];
    		static int total;
    
    };
    
    int WinkelCar::total = 0;
    If i compile this, I get this error:
    Code:
    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
    Location
    The edge of the known universe
    Posts
    32,822
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    115
    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, 08:29 AM
  2. Problem defining structure
    By MTK in forum C Programming
    Replies: 12
    Last Post: 09-08-2009, 04: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, 01:06 AM
  5. Replies: 3
    Last Post: 10-10-2002, 08:34 AM

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