月无踪 月无踪
人生就如心电图,一帆风顺说明你挂了。
关注数: 45 粉丝数: 207 发帖数: 8,876 关注贴吧数: 34
特化出现在对该模板实例的调用之后是错误的? 在能够声明或定义特化之前,它所特化的模板的声明必须在作用域中。类似地,在调用模板的这个版本之前,特化的声明必须在作用域中: // define the general compare template template <class T> int compare(const T& t1, const T& t2) { /* ... */ } int main() { // uses the generic template definition int i = compare("hello", "world"); // ... } // invalid program: explicit specialization after call template<> int compare<const char*>(const char* const& s1, const char* const& s2) { /* ... */ } This program is in error because a call that would match the specialization is made before the specialization is declared. When the compiler sees a call, it must know to expect a specialization for this version. Otherwise, the compiler is allowed to instantiate the function from the template definition. 这个程序有错误,因为在声明特化之前,进行了可以与特化相匹配的一个调用。当编译器看到一个函数调用时,它必须知道这个版本需要特化,否则,编译器将可能从模板定义实例化该函数。A program cannot have both an explicit specialization and an instantiation for the same template with the same set of template arguments. 对具有同一模板实参集的同一模板,程序不能既有显式特化又有实例化。 It is an error for a specialization to appear after a call to that instance of the template has been seen. 特化出现在对该模板实例的调用之后是错误的。
首页 5 6 7 8 9 10 下一页