Skip to content

Instantly share code, notes, and snippets.

@dionyziz
Created July 8, 2021 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dionyziz/d3210dd872c64d05e0d072e98d591b53 to your computer and use it in GitHub Desktop.
Save dionyziz/d3210dd872c64d05e0d072e98d591b53 to your computer and use it in GitHub Desktop.
/*
This has a compile error:
test3.cpp:14:18: error: use of undeclared identifier 'a'
std::cout << a;
^
1 error generated.
*/
#include <iostream>
template<typename T>
class A {
public:
A(): a(17) {}
int a;
};
template<typename T>
class B : public A<T> {
public:
void print() {
std::cout << a;
}
};
int main() {
B<int> b;
b.print();
return 0;
}
/*
This works fine.
*/
#include <iostream>
template<typename T>
class A {
public:
A(): a(17) {}
int a;
};
template<typename T>
class B : public A<int> {
public:
void print() {
std::cout << a;
}
};
int main() {
B<int> b;
b.print();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment