Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VC+;中查找不依赖于模板参数的名称+;2008年快车。是虫子吗? 在用C++模板进行实验的同时,我成功地生成了这个简单的代码,输出的结果与我对C++规则的理解不同。 void bar(double d) { std::cout << "bar(double) function called" << std::endl; } template <typename T> void foo(T t) { bar(3); } void bar(int i) { std::cout << "bar(int) function called" << std::endl; } int main() { foo(3); return 0; } 空栏(双d) { std::cout_C++_Templates - Fatal编程技术网

在VC+;中查找不依赖于模板参数的名称+;2008年快车。是虫子吗? 在用C++模板进行实验的同时,我成功地生成了这个简单的代码,输出的结果与我对C++规则的理解不同。 void bar(double d) { std::cout << "bar(double) function called" << std::endl; } template <typename T> void foo(T t) { bar(3); } void bar(int i) { std::cout << "bar(int) function called" << std::endl; } int main() { foo(3); return 0; } 空栏(双d) { std::cout

在VC+;中查找不依赖于模板参数的名称+;2008年快车。是虫子吗? 在用C++模板进行实验的同时,我成功地生成了这个简单的代码,输出的结果与我对C++规则的理解不同。 void bar(double d) { std::cout << "bar(double) function called" << std::endl; } template <typename T> void foo(T t) { bar(3); } void bar(int i) { std::cout << "bar(int) function called" << std::endl; } int main() { foo(3); return 0; } 空栏(双d) { std::cout,c++,templates,C++,Templates,这确实是编译器中的一个bug。这个问题在VS2005和之前就已经存在了(我使用Blogspot博客作为类似案例的笔记本,参见1.3)。显然,它也存在于VS2008中 您可以使用以下简单代码进行测试 int bar(double d) { return 0; } template <typename T> void foo(T t) { int i = bar(3); } void bar(int i); int main() { foo(3); } int-bar(双

这确实是编译器中的一个bug。这个问题在VS2005和之前就已经存在了(我使用Blogspot博客作为类似案例的笔记本,参见1.3)。显然,它也存在于VS2008中

您可以使用以下简单代码进行测试

int bar(double d) { return 0; }

template <typename T> void foo(T t) {
  int i = bar(3);
}

void bar(int i);

int main() {
  foo(3);
}
int-bar(双d){返回0;}
模板无效foo(T){
int i=巴(3);
}
空栏(int i);
int main(){
傅(3);
}

此代码格式良好(您可以使用Comeau Online compiler进行编译),但我打赌VS会被它卡住,因为在这种情况下,VS错误地实现了两阶段查找。

AndreyT是正确的。事实上,您的代码实际上与标准(§14.6.3/1)中的示例完全相同:

void g(双);
空h();
模板类Z{
公众:
void f(){
g(1);//调用g(double)
h++;//格式错误:无法使用递增函数;
//这可以在这里诊断,也可以在这里诊断
//在实例化的时候
}
};
void g(int);//不在模板点的范围内
//定义,不考虑呼叫g(1)

如果你是对的,你不会感到惊讶。在我看来,VC++对模板的实现完全忽略了依赖/非依赖问题。VC++从不遵守标准的2次通过评估(第一次是在阅读模板定义时,第二次是在模板实例时)。它可以在某些地方保存书写
typename
template
,但…不符合要求。为了精确起见,您参考了标准的第14.6.3节非依赖名称[temp.nondep](最终草案)是的,VS(至少我的快速版本,但我认为其他版本中的编译器是相同的)声明代码中有错误。谢谢。
void g(double);
void h();

template<class T> class Z {
public:
    void f() {
        g(1);    //calls g(double)
        h++;     //ill-formed: cannot increment function;
                 // this could be diagnosed either here or
                 // at the point of instantiation
    }
};

void g(int);     // not in scope at the point of the template
                 // definition, not considered for the call g(1)