0
我收到此错误:C++ - 错误LNK2001:解析外部符号
1>Exception.obj : error LNK2001: unresolved external symbol "public: static struct SDL_Window * Exception::window" ([email protected]@@[email protected]@A)
每次我试图编译程序
。我明显错过了一些东西,但是我看不到我做错了什么......我该如何解决这个错误?以下是文件:
Exception.h:
#pragma once
#include <SDL.h>
#include <stdio.h>
class Exception
{
public:
static SDL_Window* window;
static enum ErrorMessageType{ CONSOLE, WINDOW, BOTH };
static void initialize(SDL_Window* window);
static void showErrorMessage(const char* error, Exception::ErrorMessageType messageType);
};
Exception.cpp
#include "Exception.h"
void Exception::initialize(SDL_Window* window)
{
Exception::window = window;
}
void Exception::showErrorMessage(const char* error, Exception::ErrorMessageType messageType)
{
switch (messageType)
{
case Exception::CONSOLE:
printf("\n%s\n", error);
break;
case Exception::WINDOW:
SDL_ShowSimpleMessageBox(0, "Error", error, window);
break;
case Exception::BOTH:
printf("\n%s\n", error);
SDL_ShowSimpleMessageBox(0, "Error", error, window);
break;
}
}
错误。静态关键字不属于这里,并会导致编译器错误。 –
@SamVarshavchik复制粘贴错误,已更正 – Steephen