0

Another C++ template issue, and I have no idea where it is coming from. My only guess is that the template constructor is not synthesized? (Even the term synthesized is from my ObjC background, not great with C++)

All I could do is simplify the code as much as I can, while maintaining the error. Now, if I remove the State constructor, the error goes away .. But I need some constructors to work with.

State

template<typename T>
class State {
public:

    State();

};

#include "State.h"


template<typename T>
State<T>::State()
{}

Match

#include "State.h"

class Match {
public:

    State<Match> *currentState;

    struct States {
        static State<Match> Playing;
    };

};

#include "Match.h"

State<Match> Match::States::Playing;

Error

Undefined symbols for architecture x86_64:
  "State<Match>::State()", referenced from:
      ___cxx_global_var_init in Match.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Mazyod
  • 22,319
  • 10
  • 92
  • 157
  • Do the main books not talk about this? Or they do and why are people not reading them? This comes up daily. :( – Lightness Races in Orbit Apr 09 '15 at 19:10
  • @LightningRacisinObrit Nobody reads books any more. Actually I never read a book either. – Neil Kirk Apr 09 '15 at 19:14
  • @NeilKirk: People absolutely read books! And they _should_. However I do believe that more and more people are lazily using internet "tuts" and references instead of actually investing the time to study and learn things. That would explain the wealth of crappy questions on SO every day. =) – Lightness Races in Orbit Apr 09 '15 at 19:23
  • @LightningRacisinObrit I read a C++ book, once, but forgot all the details. Why can't we just blame the compiler? – Mazyod Apr 09 '15 at 19:24
  • freaking C++ gang .. You should learn from the Android and iOS users – Mazyod Apr 09 '15 at 19:53

0 Answers0