2017-12-23 7 views
0

でリンク2001エラーが発生しました。私の小さなプログラムで複数のファイルがありましたが、私のヘッダーファイルとcppファイルの間にlink2001エラーが発生しています。未解決の外部シンボル

struct startup 
{ 
    static std::string latestVersion; 
    static std::string currentVersion; 
    static std::string latestUpdate; 
    static bool upToDate; 
    static void checkUpToDate(); 
    static void consoleStartup(); 

}; 

私のヘッダファイルであり、ここに私のcppファイルであること:

#include "stdafx.h" 
#include <Windows.h> 
#include <iostream> 
#include <string> 

void startup::checkUpToDate() 
{ 
    if (startup::currentVersion == startup::latestVersion) 
    { 
     startup::upToDate = true; 
    } 
    if (startup::currentVersion != startup::latestVersion) 
    { 
     startup::upToDate = false; 
    } 
} 
void startup::consoleStartup() 
{ 
    startup::checkUpToDate(); 
    HANDLE hConsole; 
    hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 
    FlushConsoleInputBuffer(hConsole); 
    SetConsoleTextAttribute(hConsole, color::red); 
    std::cout << R"(
     _,.-------.,_ 
    ,;~'    '~;, 
    ,;      ;, 
    ;       ; 
,'       ', 
,;       ;, 
; ;  .   .  ; ; 
| ; ______  ______ ; | 
| `/~"  ~" . "~  "~\' | 
| ~ ,-~~~^~, | ,~^~~~-, ~ | 
| |  }:{  | | 
| l  /| \  ! | 
.~ (__,.--" .^. "--.,__) ~. 
|  ---;'/| \ `;---  | 
    \__.  \/^\/  .__/ 
    V| \    /|V 
    | |T~\___!___!___/~T| | 
    | |`IIII_I_I_I_IIII'| | 
    | \,III I I I III,/ | 
    \ `~~~~~~~~~~' /
     \ .  . / 
     \. ^ ./ 
)" << std::endl; 

    SetConsoleTextAttribute(hConsole, color::green); 
    std::cout << "---------------------The ----------------------" << std::endl; 
    SetConsoleTextAttribute(hConsole, color::purple); 
    if (startup::upToDate == true) 
    { 
     std::cout << "  [You are all up to date! Your version: " + startup::currentVersion + " Latest version: " + startup::latestVersion + "]" << std::endl; 
    } 
    else if (startup::upToDate == false) 
    { 
     std::cout << "  [You are running on a old update! Your version: " + startup::currentVersion + " Latest version: " + startup::latestVersion + "]" << std::endl; 
    } 
    SetConsoleTextAttribute(hConsole, color::white); 
} 

私は別のファイルに移動し、main.cppに内のすべてを持っていた前に、すべてがうまく働きました。私は間違って何をしているのか100%確信しているわけではありませんが、私はlink2001のエラーを知っていますが、私はそれを修正することができないようです。

私のコードも非常に悪いかもしれ、まだ、事前に感謝を学ぶ:)

また、ここでイムはエラーメッセージです:

Severity Code Description Project File Line Suppression State 
Error LNK2001 unresolved external symbol "public: static bool startup::upToDate" ([email protected]@@2_NA) FileEncryptionDecryptions C:\Users\Jonitoi\Desktop\Projects\Visual Studio\cpp\FileEncryptionDecryptions\FileEncryptionDecryptions\startup.obj 1 
+2

ビルドERRについての質問を投稿するときは –

+0

カントーASCIIの頭蓋骨は、あなたは完全なエラーメッセージ – Asesh

+1

を投稿する必要があることorsは常に完全な完全な出力を(テキストとして)コピーし、変更なしで質問本体に貼り付けます。しばらく時間を取って[良い質問をする方法を読む](http://stackoverflow.com/help/how-to-ask)を参照してください。 –

答えて

0

upToDateあなたがそれを初期化する必要がありますので、静的メンバ変数でありますグローバルスコープで:

struct startup 
{ 
    static std::string latestVersion; 
    static std::string currentVersion; 
    static std::string latestUpdate; 
    static bool upToDate; 
    static void checkUpToDate(); 
    static void consoleStartup(); 
}; 

bool startup::upToDate = false; 
関連する問題