小编Lau*_*ura的帖子

以这种方式设计方法是否有必要的原因

我正在阅读Sedgewick的Algorithms 4th.第165页有消费税

编写一个方法remove() ,将链表和字符串键作为参数,并删除列表中具有键作为其项字段的所有节点.

我认为链表参数是多余的,因为实例方法始终使用对象名称进行调用.那么为什么作者希望它作为一个参数传递?(我不认为将remove()写为静态方法比实例方法更好.)

java data-structures

2
推荐指数
1
解决办法
70
查看次数

带const的模板函数参数

我知道参考不是点.引用不是对象.所以没有const引用.

const int ci = 1024;
const int &rl = ci;
Run Code Online (Sandbox Code Playgroud)

我们不能写int const &rl = ...但是今天,我学习二叉树源代码:

template <typename T> //take e as the node insert the left child of the tree.
BinNodePosi(T) BinNode<T>::insertAsLC(T const & e) {  return lChild = new BinNode(e, this);  }
Run Code Online (Sandbox Code Playgroud)

我对它的参数感到困惑:T const&e.为什么不是const T&e?我认为后者是对的..也许我的问题太简单了,不能在这里发布.与数学不同,研究水平和学习水平分别有两个方面:MathOverFlow和math.stackexchange ..我找不到stackoverflow的初级网站..所以我在这里发布.请原谅我.非常感谢.

c++ data-structures

2
推荐指数
1
解决办法
79
查看次数

为什么`CClientDC dc(this);`不能替换为`CClientDC dc = CClientDC(this);`

我是MFC编程的新手.这些天我使用Jeff Prosise的书来学习MFC编程.我遇到过:CClientDC dc (this);我从CClientDC类的定义中找到了一个构造函数:CClientDC(CWnd* pWnd);但是如果我替换CClientDC dc (this);CClientDC dc = CClientDC(this);.编译告诉我这是一个错误.我无法理解.我认为CClientDC dc (this);是一样的CClientDC dc = CClientDC(this);.或者换句话说,前者是一种简单的形式.

非常感谢.

c++ mfc visual-c++

1
推荐指数
1
解决办法
1145
查看次数

标签 统计

c++ ×2

data-structures ×2

java ×1

mfc ×1

visual-c++ ×1