SWにリンカーエラーがあります。私はh、hpp、cppファイルに基づいて次の構造を使用しています。一部のクラスはテンプレート化されており、一部はテンプレート化されておらず、一部には関数テンプレートがあります。SWには何百ものクラスが含まれています...
宣言:
test.h
#ifndef TEST_H
#define TEST_H
class Test
{
public:
template <typename T>
void foo1();
void foo2 ();
};
#include "test.hpp"
#endif
意味:
test.hpp
#ifndef TEST_HPP
#define TEST_HPP
template <typename T>
void Test::foo1() {}
inline void Test::foo2() {} //or in cpp file
#endif
CPPファイル:
test.cpp
#include "test.h"
void Test::foo2() {} //or in hpp file as inline
次の問題があります。変数vars[]は私のhファイルで宣言されています
test.h
#ifndef TEST_H
#define TEST_H
char *vars[] = { "first", "second"...};
class Test
{
public: void foo();
};
#include "test.hpp"
#endif
インラインとしてhppファイルで定義されたfoo()メソッド内のローカル変数として使用されます。
test.hpp
#ifndef TEST_HPP
#define TEST_HPP
inline void Test::foo() {
char *var = vars[0]; //A Linker Error
}
#endif
ただし、次のリンカエラーが発生します。
Error 745 error LNK2005: "char * * vars" (?vars@@3PAPADA) already defined in main.obj
リンカエラーを回避するためにvars[]を宣言する方法と場所は?含めた後
#include "test.hpp"
それを宣言するのは遅いです...
私が書いたように、ソフトウェアには多くのcppが含まれており、hppファイルは互いにインクルードされています(すべてのインクルードがチェックされています)。例全体を送信することはできません...
main.objは、メインクラスを含むファイルを表します。