2
#include <cstddef>
#include <iostream>
template<std::size_t R, std::size_t C>
struct foo {};
template<std::size_t R, std::size_t C>
class bar {
public:
bar(const foo<R, C>& = foo<R, C>()) {}
};
int main() {
bar<10, 10> y;
std::cout << 'x';
}
上述代碼compiles and runs correctly(打印x
作爲輸出)對於g ++ V4.8,而同樣does not even compile上鐺++ V3.4,聲稱一個error: unknown type name 'C'
。爲什麼兩個版本的編譯結果不同?爲什麼不用鏗鏘聲++編譯與g ++相同的文件?
用於編譯的命令有:
g++-4.8 -std=c++11 -O2 -Wall -pedantic -pthread main.cpp && ./a.out
clang++ -std=c++11 -O2 -Wall -pedantic -pthread main.cpp && ./a.out
至少應該在其中定義'std :: size_t'的頭部包含。 – juanchopanza
@ juanchopanza,絕對正確,固定。 (當然的問題仍然存在) – Shoe
看起來像編譯器故障 – uk4321