Moderators: phlip, Moderators General, Prelates
Terry Pratchett wrote:The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <iostream>
int foo(double d)
{
return 1;
}
template<typename T>
int bar()
{
// The standard says that, because the resolution of 'foo'
// doesn't depend on what template parameter is passed
// the name is bound at template definition time -- and the
// only thing in scope now is foo(double). This is what GCC
// does.
return foo(1);
}
int foo(int i)
{
return 2;
}
int main()
{
// However, MSVC delays name lookup until instantiation
// time, which is now. And now, 'foo(int)' is in scope -- and
// that's a better overload, so overload resolution picks it
// for the 'foo(1)' call.
//
// Thus MSVC prints 2 here, while G++ prints 1.
std::cout << bar<int>() << "\n";
}Terry Pratchett wrote:The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.
template<typename T, typename TBar>
struct Foo : TBar
{
typedef Foo<T, typename TBar::Baz<T>> SpecificFoo;
};
struct MyBar
{
template<typename T>
struct Baz
{
};
};
int main()
{
Foo<int, MyBar> foo;
}template<typename T, typename TBar>
struct Foo : TBar
{
typedef Foo<T, typename TBar::template Baz<T>> SpecificFoo;
};
struct MyBar
{
template<typename T>
struct Baz
{
};
};
int main()
{
Foo<int, MyBar> foo;
}Terry Pratchett wrote:The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.
template<typename T>
void foo() {
bar();
}
void bar() {}
... foo<int>();Terry Pratchett wrote:The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.
Terry Pratchett wrote:The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.
Users browsing this forum: Bakstoola and 4 guests