用g ++链接C++中的错误

Saj*_*ani 4 c++ linker g++

请看下面的程序.为什么我收到错误?

#include <stdlib.h>
#include <string>
#include <string.h>
#include <iostream>


using namespace std;

class serverData
{
public:
    static int serverTemp;
    static int server;
};
int main(int argc, char** argv)
{
    string s = "sajad bahmani";
    serverData::server = 90 ;

    const char * a = s.data();
    cout << a[0] << endl;

    return (EXIT_SUCCESS);
}
Run Code Online (Sandbox Code Playgroud)

结合起来,我在尝试链接时遇到此错误:

build/Debug/GNU-Linux-x86/main.o: In function `main':
/home/sb23/pr/main.cpp:14: undefined reference to `serverData::server'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

Rog*_*mbe 8

静态成员变量必须在您的一个.CPP文件中分配存储:

/* static */
int serverData::serverTemp;
int serverData::server;
Run Code Online (Sandbox Code Playgroud)