The following code works.
/* hello.cc */
#include <iostream>
#include <vector>
void vec_print()
{
std::vector<int> is(10, 1);
for (size_t i = 0; i < is.size(); ++i)
std::cout << is[i] << " ";
std::cout << std::endl;
}
/* main.cc */
void vec_print();
int main()
{
vec_print();
}
When i complie this with
g++ -fno-implicit-templates -Wall -Wextra -c hello.cc
g++ -fno-implicit-templates -Wall -Wextra -c main.cc
g++ hello.o main.o -o hello
I get no warnings and it compiles and runs fine. I am under the impression this shouldn’t happen. I am using gcc 4.4.5.
That option doesn’t prevent all template instantiations, just non-inline ones:
The compiler inlines all the
vectormember functions used in your code, so compilation succeeds.The following will fail when compiled with that option, since it requires a non-inline instantiation: