[Qt-interest] Error in defining a static data member to a class

Akshey Jawa aksheyjawa at gmail.com
Thu Oct 29 17:36:10 CET 2009


Thanks a lot. The in-class definition gave a compilation error. But the
defining in .cpp file worked!
Is it some problem with Qt or the same applies to other compilers too ? I am
not an experienced programmer.

Thanks,
Akshey

On Thu, Oct 29, 2009 at 1:36 AM, Constantin Makshin <
dinosaur-rus at users.sourceforge.net> wrote:

> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091029/1188e872/attachment.html 


More information about the Qt-interest-old mailing list