也许您是一位C++老手了,不妨来看看,也许有点学院派的味道

sevencat 2004-03-15 11:33:07
一、这样能编译成功吗?假如能的话,能得到正确有答案吗?
是一个菲波拉契数.
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);
}
...全文
55 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
danielzhu 2004-03-15
  • 打赏
  • 举报
回复
up

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧