When I compile the following with g++ --std=c++98 -Wall -Werror -Wpedantic Test.cc, there's no error.
template <class T>
struct TemplateClass {
T *ptr;
TemplateClass(T *p): ptr(p) {}
int foo() {
retu ptr->bar();
}
};
struct ExampleClass {
};
int main() {
TemplateClass<ExampleClass> x(new ExampleClass());
}
I expected that the compiler would complain that ExampleClass doesn't implement method bar.
But it looks like it only complains if I actually use the method foo.
Can I rely on this behavior on any C++98 and C++11 compliant compilers?
My understanding of templates before was that whenever a template is instantiated, the entirety of the body is copied with T replaced with the template argument. Is this not how templates work?
