0

I'm encountering a strange bug. I appear to be using explicit instantiation properly, however I am getting an "unresolved external symbol" error when compiling.

Here is what is happening:

code.h

#pragma once

template <typename T>
struct A {
    void foo() const;
};

template <typename T>
struct B : public A<T> {};

typedef B<int> C;

code.cpp

#include "code.h"

template <typename T>
void A<T>::foo() const {}

template struct B<int>;

main.cpp

#include "code.h"

int main() {

    C test;
    test.foo()  // <----- unresolved external symbol

    return 0;

}

As far as I can tell, I'm doing almost exactly what this guy is doing, except with inheritance thrown into the mix. Why is this erroring? If it helps, I am using Visual Studio 2017.

1 Answers1

0

I figured it out. If you look here in code.h:

template <typename T>
struct B : public A<T> {};

You see that I am using A<T>, which also needs to be explicitly instantiated.