0

I try to run my C++ code in Visual Studio 2013. The code was running in the past the gcc 4.9

I don't know why the code is in Visual Studio not running. I upload the code to GitHub so that everyone can take a look at it. Please help me. I really don't know why the code is not running in Visual Studio.

Error   1   error LNK2019: unresolved external symbol "public: __thiscall ********::Property::Property<int,1>::Property<int,1>(class std::function<int __cdecl(void)> const &,class std::function<void __cdecl(int)> const &)" (??0?$Property@H$00@Property@********@@QAE@ABV?$function@$$A6AHXZ@std@@ABV?$function@$$A6AXH@Z@4@@Z) referenced in function _main    C:\Users\#######\documents\visual studio 2013\Projects\********\Property\PropertyTest.obj   Property
Error   2   error LNK2019: unresolved external symbol "public: __thiscall ********::Property::Property<int,1>::operator int const (void)" (??B?$Property@H$00@Property@********@@QAE?BHXZ) referenced in function _main C:\Users\#######\documents\visual studio 2013\Projects\********\Property\PropertyTest.obj   Property
Error   3   error LNK2019: unresolved external symbol "public: int __thiscall ********::Property::Property<int,1>::operator=(int const &)" (??4?$Property@H$00@Property@********@@QAEHABH@Z) referenced in function _main   C:\Users\#######\documents\visual studio 2013\Projects\********\Property\PropertyTest.obj   Property
Error   4   error LNK2019: unresolved external symbol "public: int __thiscall ********::Property::Property<int,1>::operator+=(int const &)" (??Y?$Property@H$00@Property@********@@QAEHABH@Z) referenced in function _main  C:\Users\#######\documents\visual studio 2013\Projects\********\Property\PropertyTest.obj   Property
Error   5   error LNK2019: unresolved external symbol "public: int __thiscall ********::Property::Property<int,1>::operator-=(int const &)" (??Z?$Property@H$00@Property@********@@QAEHABH@Z) referenced in function _main  C:\Users\#######\documents\visual studio 2013\Projects\********\Property\PropertyTest.obj   Property
Error   6   error LNK2019: unresolved external symbol "public: int __thiscall ********::Property::Property<int,1>::operator*=(int const &)" (??X?$Property@H$00@Property@********@@QAEHABH@Z) referenced in function _main  C:\Users\#######\documents\visual studio 2013\Projects\********\Property\PropertyTest.obj   Property
Error   7   error LNK2019: unresolved external symbol "public: int __thiscall ********::Property::Property<int,1>::operator/=(int const &)" (??_0?$Property@H$00@Property@********@@QAEHABH@Z) referenced in function _main C:\Users\#######\documents\visual studio 2013\Projects\********\Property\PropertyTest.obj   Property
Error   8   error LNK2019: unresolved external symbol "public: int __thiscall ********::Property::Property<int,1>::operator%=(int const &)" (??_1?$Property@H$00@Property@********@@QAEHABH@Z) referenced in function _main C:\Users\#######\documents\visual studio 2013\Projects\********\Property\PropertyTest.obj   Property
Error   9   error LNK2019: unresolved external symbol "public: __thiscall ********::Property::Property<int,2>::Property<int,2>(class std::function<int __cdecl(void)> const &)" (??0?$Property@H$01@Property@********@@QAE@ABV?$function@$$A6AHXZ@std@@@Z) referenced in function _main C:\Users\#######\documents\visual studio 2013\Projects\********\Property\PropertyTest.obj   Property
Error   10  error LNK2019: unresolved external symbol "public: __thiscall ********::Property::Property<int,2>::operator int const (void)" (??B?$Property@H$01@Property@********@@QAE?BHXZ) referenced in function _main C:\Users\#######\documents\visual studio 2013\Projects\********\Property\PropertyTest.obj   Property
Error   11  error LNK2019: unresolved external symbol "public: __thiscall ********::Property::Property<int,3>::Property<int,3>(class std::function<void __cdecl(int)> const &)" (??0?$Property@H$02@Property@********@@QAE@ABV?$function@$$A6AXH@Z@std@@@Z) referenced in function _main    C:\Users\#######\documents\visual studio 2013\Projects\********\Property\PropertyTest.obj   Property
Error   12  error LNK2019: unresolved external symbol "public: void __thiscall ********::Property::Property<int,3>::operator=(int)" (??4?$Property@H$02@Property@********@@QAEXH@Z) referenced in function _main    C:\Users\#######\documents\visual studio 2013\Projects\********\Property\PropertyTest.obj   Property
Error   13  error LNK1120: 12 unresolved externals  C:\Users\#######\documents\visual studio 2013\Projects\********\Debug\Property.exe  Property

[Closed]

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Heinrich
  • 307
  • 4
  • 12
  • First THANK YOU. Now It worked. Is it not possible to split template classes to .h and .cpp files? Must I implement the hole code to the header File? Because the code was already running with gcc 4.9 with .h and .cpp splited. It this may be a gcc special? – Heinrich Jun 06 '14 at 22:45
  • You can split them up, and `#include` the cpp also. There's nothing special about gcc in this regard, you must've done something different without realizing it. – Praetorian Jun 06 '14 at 22:47
  • @Praetorian How to set your comment as the right answer? Or is it not possible because it's "only" a comment? – Heinrich Jun 06 '14 at 23:04
  • You can't select a comment as an answer. Don't worry about it, 2 more votes and this will be closed as a duplicate, so just leave it. In fact, you yourself could cast a vote too to hasten the process :) – Praetorian Jun 06 '14 at 23:06
  • This has nothing whatsoever with GitHub. Please be careful when selecting tags. – ChrisGPT was on strike Jun 07 '14 at 00:16
  • Sorry Chris. I forgot to delete the GitHub Tag after I remove the link to the source code. In the beginning I made the source code available. For this I used GitHub. – Heinrich Jun 07 '14 at 18:55

1 Answers1

1

Like Praetorian wrote, Template Classes can not be easiely splited into Header (.h) and Source (.cpp) Files. The reason is that "the compiler creates a new class with the given template argument." quote

My Solution to split Template Classes into Header (.h) and Source (.cpp) Files looks like this:

// HEADER File test.h
#ifndef __TEST_FH__
#define __TEST_FH__

template<typename T>
class test {
public:
    T object;

    test();
    ~test();
};

#include "test.cpp"

#endif



// SOURCE File test.cpp
#ifdef __TEST_FH__
#ifndef __TEST_SOURCE_FH__
#define __TEST_SOURCE_FH__

template<typename T>
test::test() {
    //code
}

template<typename T>
test::~test() {
    //code
}

#endif
#endif

Once more thank you very much Praetorian.

Community
  • 1
  • 1
Heinrich
  • 307
  • 4
  • 12