Ich will ein struct haben das eine staic Variable enthält. Die statiche Variable soll dann durch ein Funktion kontrolliert werden.
hier erstmal der quelltext:
main.cpp:
Code:
#include "types.h"
int main()
{
foobar();
}
-----------------------------------------------------------------------
dann die header datei types.h:
Code:
#ifndef TYPES
#define TYPES 1
struct CTypes
{
static int anzahl;
int foo;
int irgendwas;
};
int CTypes::anzahl=0;
int foobar();
#endif
-------------------------------------------------
und zum schluss noch die types.cpp:
Code:
int foobar()
{
CTypes::anzahl++;
}
wenn ich es komplieren will kommt:
g++ -c types.cpp;g++ main.cpp types.o
types.o(.bss+0x0): multiple definition of `CTypes::anzahl'
/tmp/ccK3BVur.o(.bss+0x0): first defined here
collect2: ld returned 1 exit status
mhhh, wenn ich bei "int CTypes::anzahl=0;" das int aber weglass meckert er auch..
Und wenn ich die "int CTypes::anzahl=0;" ganz weg lass dann ist die statische Variable ja nicht zugeweisen
auch das zuweisen der 0 gleich im struct ist nicht gestattet
mhhh, ich weis echt nich weiter wie das gehen soll..
Lesezeichen