0

VS 2012 で単体テストを定義しましたが、エラー C2338 が原因でコンパイルできません。

エラー C2338: テスト ライターは、クラス class std::basic_string,class std::allocator > __cdecl Microsoft::VisualStudio::CppUnitTestFramework::ToString(const struct CoreUnitTests::TestStruct &) の ToString の特殊化を定義する必要があります。c:\program files (x86)\microsoft Visual Studio 11.0\vc\unittest\include\cppunittestassert.h

これは、Assert::AreEqual テストを行うときに発生します。この型の ToString メソッドを定義する必要があります。

cppunittestassert.h に記載されているガイダンスに従い、インターネットで解決策を見つけました。ただし、エラーはまだ発生しています。

私が使用しているコードの例を次に示します。

struct TestStruct
{
public:
    float f;
    int i;

    bool operator == (const TestStruct& rhs) const
    {
        return (f == rhs.f) && (i == rhs.i);
    }
};

namespace Microsoft
{ 
    namespace VisualStudio
    { 
        namespace CppUnitTestFramework
        {
        template<> 
        static std::wstring ToString<TestStruct>(const TestStruct& t)
        { 
            std::wstringstream stream;
            stream << "TestStruct";
            return stream.str();
        }
        }
    }
}

私は明らかにまだ何か間違ったことをしています。誰でもアイデアはあります。私はすでに TestStruct* バージョンを追加しようとしましたが、それは役に立ちません。

名前空間と関係があるのではないかと思いますが、この問題を解決する方法がわかりません。

ありがとう

4

0 に答える 0