I'm wondering if anyone has a good explanation of this. Essentially, when using a template specialization, the "inline" keyword is making the difference between compilable and non-compilable code (gcc v4.1.2). Here's my bare-bones example:
Code:
//file: header.h
#ifndef HEADER_H
#define HEADER_H

#include <iostream>

template<class T>
void foo(T val){
  std::cout << "foo<T>("<<val<<")\n";
}

template<>
inline void foo(double val){
  std::cout << "foo<double>(" << val <<")\n";
}

#endif
Code:
//file: main.cpp
#include "header.h"

int main(){
  double x=4;
  foo(x);
  return 0;
}
Code:
//file:  somecode.cpp
#include "header.h"
void somecode(){}
This compiles fine if the "inline" keyword is included in the template specialization in header.h, but without "inline", the compiler spits out "multiple definition of `void foo<double>(double)'" at the linking phase. Does anybody have a good explanation of the role of "inline" in this example?