文章分类 -  Puzzles

These problems may puzzle you ever, now I list them. You'd face with them. Put your puzzles here, I'll pick some up and share to others.
摘要:#include <iostream>using namespace std;template <typename T>class X{ T m_val;public: friend auto operator<<(ostream &o, const X &x) -> ostream &;};template <typename T>auto operator<<(ostream &o, const X<T> &x) -> ostream &{ return o 阅读全文
posted @ 2012-09-20 19:53 walfud 阅读(205) 评论(0) 推荐(0) 编辑
摘要:当函数声明和使用放在同一函数体内时, 则 ADL 不会向现有的重载函数集合中添加任何函数. 阅读全文
posted @ 2012-02-14 15:38 walfud 阅读(249) 评论(0) 推荐(0) 编辑
摘要:在 C++ 中, 函数的调用有时很简单:// code 1void foo(){}int main() { foo(); return 0;}有时可能很复杂:// code 2namespace NA{ class CA {}; void foo(CA &) {}}int main() { NA::CA ca; foo(ca); return 0;}下面我就总结一下 C++ 中的 Name Lookup.当编译器遇到一个函数调用时:Koenig Name Lookup: 查找当前命名空间中是否有匹配的函数声明. 如果函数中有类类型的参数,... 阅读全文
posted @ 2012-01-12 22:03 walfud 阅读(2032) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2012-01-10 17:24 walfud 阅读(179) 评论(0) 推荐(0) 编辑
摘要:// vs 2010//#inlcude "stdafx.h"#include <iostream>using namespace std; int main(int argc, char *argv[]){ string str; cout <<str <<endl; // Compilation error. return 0;}当你写下这样的代码时你将会得到一大堆的编译错误, 其中比较有用的在第一行:error C2679: binary '<<' : no operator found which ta 阅读全文
posted @ 2012-01-10 16:44 walfud 阅读(4424) 评论(2) 推荐(2) 编辑
摘要:char * const *(*next)() ; 这种声明你能理解么? 阅读全文
posted @ 2011-07-19 21:08 walfud 阅读(493) 评论(0) 推荐(0) 编辑
摘要:因为 char * 与 const char * 不是同一类型. 阅读全文
posted @ 2011-07-17 19:28 walfud 阅读(1411) 评论(0) 推荐(0) 编辑
摘要:#define cat(x,y) x ## y#define xcat(x, y) cat(x,y)....// 有如下调用int main(){ ... cat(1, 2) ; // OK , 这是没问题的 cat(cat(1, 2), 3) ; // Error , 这里就有问题了, 据说会解析成 'cat ( 1 , 2 )3' xcat(cat(1, 2), 3) ; // OK , 这又是问什么呢? 加了一层就好了? ... return 0 ;}解答:#与##在宏定义中的--宏展开#include <stdio.h>#define f(a,b) a##b 阅读全文
posted @ 2011-04-08 13:37 walfud 阅读(280) 评论(0) 推荐(0) 编辑