Created
July 8, 2021 17:13
-
-
Save dionyziz/d3210dd872c64d05e0d072e98d591b53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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