1

I was going through this link to learn about the typename keyword and doing some experiments

Following is the code ->

template<typename T>
void foo(T& t) {
    T::i = 6;
}

class A {
public:
    static int i;
    int j;
};

int main() {
    A a;
    foo(a);
}

I am getting linker error mentioning

undefined reference to `A::i'

If I do t.j = 6; instead of T::i = 6;, program compiles and runs successfully.

Compiler - g++ 4.8.4 on linux ubuntu

Thanks

  • 1
    Specifically read the last part of this [answer](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix/12574407#12574407) – πάντα ῥεῖ Aug 25 '18 at 15:08

0 Answers0