[Qt-interest] Error in defining a static data member to a class
Constantin Makshin
dinosaur-rus at users.sourceforge.net
Wed Oct 28 21:06:20 CET 2009
Either define it in the class declaraion
class ClassName
{
static int temp = 0;
};
or in one of your .cpp files
// someclass.h
class ClassName
{
static int temp;
};
// someclass.cpp
#include "someclass.h"
int ClassName::temp = 0;
On Wed, 28 Oct 2009 14:21:46 +0300, Akshey Jawa <aksheyjawa at gmail.com>
wrote:
> Hi,
>
> I am getting an error in defining a static data member to a class. The
> declaration of the static member does not give any error but when I
> define the variable then I get an the error. Example--
>
> I got error for this statement-
> *int ClassName::temp=0;*
>
> *Error:* multiple definition of `ClassName::temp'.
> first defined here:
> main.o:/usr/include/c++/4.2/bits/locale_facets.tcc:2560
>
> I have tried changing the names of the identifiers and also tried
> introducing static data members in some other working code, but I get
> similar errors. I am using Qt Creator but I get same error on command
> line also.
>
> Please help
>
> Regards,
> Akshey
--
Constantin Makshin
More information about the Qt-interest-old
mailing list