一、这样能编译成功吗?假如能的话,能得到正确有答案吗?
是一个菲波拉契数.
f(n)=f(n-1)+f(n-2); template<int n>
struct Fib { static int Value; }; template <>
int Fib<0>::Value = 0; template <>
int Fib<1>::Value = 1; template<int n>
int Fib<n>::Value = Fib<n-1>::Value + Fib<n-2>::Value; int f ()
{
return Fib<40>::Value;
}int f3()
{
return Fib<3>::Value;
}二、这样能编译通过吗?假如能的话,最后一个函数里的x到底是什么东东?
struct A { int i; struct i {}; };
struct B { int i; struct i {}; };
struct D : public A, public B { using A::i; void f (); };
void D::f () { struct i x; }三、这是常见的了,哪些是有问题的?
i = v[i++];
i = 7, i++, i++; i = ++i + 1;
i = i + 1; 四、下面这个哪一个行不能编译
struct S {
typedef struct A {} A;
typedef struct B B;
typedef A A;
};五、下面的代码有问题吗?能得到正确答案吗?
struct A {
template< typename T > operator T() const;
} a; template<> A::operator float() const
{
return 1.0f;
} int main()
{
float f = 1.0f * a;
}六、下面这段代码在你的编译器上能编译成功吗?
struct S {
static int const I = 42;
}; template<int N> struct X {}; template<typename T> void f(X<T::I>*) {} template<typename T> void f(X<T::J>*) {} int main() {
f<S>(0);
}七、这段代码有问题吗?
template<int i> class A { /* ... */ };
template<int i> void g(A<i+1>);
template<int i> void f(A<i>, A<i+1>);
void k() {
A<1> a1;
A<2> a2;
g(a1);
g<0>(a1);
f(a1, a2);
}
是一个菲波拉契数.
f(n)=f(n-1)+f(n-2); template<int n>
struct Fib { static int Value; }; template <>
int Fib<0>::Value = 0; template <>
int Fib<1>::Value = 1; template<int n>
int Fib<n>::Value = Fib<n-1>::Value + Fib<n-2>::Value; int f ()
{
return Fib<40>::Value;
}int f3()
{
return Fib<3>::Value;
}二、这样能编译通过吗?假如能的话,最后一个函数里的x到底是什么东东?
struct A { int i; struct i {}; };
struct B { int i; struct i {}; };
struct D : public A, public B { using A::i; void f (); };
void D::f () { struct i x; }三、这是常见的了,哪些是有问题的?
i = v[i++];
i = 7, i++, i++; i = ++i + 1;
i = i + 1; 四、下面这个哪一个行不能编译
struct S {
typedef struct A {} A;
typedef struct B B;
typedef A A;
};五、下面的代码有问题吗?能得到正确答案吗?
struct A {
template< typename T > operator T() const;
} a; template<> A::operator float() const
{
return 1.0f;
} int main()
{
float f = 1.0f * a;
}六、下面这段代码在你的编译器上能编译成功吗?
struct S {
static int const I = 42;
}; template<int N> struct X {}; template<typename T> void f(X<T::I>*) {} template<typename T> void f(X<T::J>*) {} int main() {
f<S>(0);
}七、这段代码有问题吗?
template<int i> class A { /* ... */ };
template<int i> void g(A<i+1>);
template<int i> void f(A<i>, A<i+1>);
void k() {
A<1> a1;
A<2> a2;
g(a1);
g<0>(a1);
f(a1, a2);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货