在深入浅出MFC中的代码:(为了方便简写了)
class Doc{
public:
CTypedPtrList<CObList,CStroke*> m_strokeList;
}........ .......
.... ...... ...... ............ ...........
class View{
...... ........ ........ ..........
Doc* pdoc=GetDocument();
CTypedPtrList<CObList,CStroke*> & strokeList=pdoc->m_strokeList;
就是上面这句!是应该返回strokeList还是strokeList的引用?一定要说出为什么!多谢! 还有那个View是怎麽生成的,和Pcontext有什麽关系?请指点!
class Doc{
public:
CTypedPtrList<CObList,CStroke*> m_strokeList;
}........ .......
.... ...... ...... ............ ...........
class View{
...... ........ ........ ..........
Doc* pdoc=GetDocument();
CTypedPtrList<CObList,CStroke*> & strokeList=pdoc->m_strokeList;
就是上面这句!是应该返回strokeList还是strokeList的引用?一定要说出为什么!多谢! 还有那个View是怎麽生成的,和Pcontext有什麽关系?请指点!
解决方案 »
- 问题: 内存位置 0x0012f624 处的 boost::exception_detail::clone_impl<boost::exception_deta
- 拦截所有IP包
- vc 怎么使得自己的代码积累更容易的应用于其它工程??
- 传输数据的问题!!!!!!!
- ¥¥¥¥这样的东东值多少大洋——会快速结贴的
- 用WM_SETTEXT,EN_UPDATE,EN_CHANGE,WM_KILLFOCUS不能解决之问题
- 我知道了一个文件的句柄后,请问应该怎么样才能得到它的路经?
- 问个小问题?
- 特急:如何用一幅真彩jpg图片作为Dialog的背景图片,并且该图片要保存在资源文件中。请高手指点,百分相送,多谢了!
- 请斑竹不要删,因为这里高手比较多,关于WIN2000中影射网络驱动器的问题
- Programming windows中关于绘图的一个疑问!
- 如何得到对话框下的一个控件的RECT位置?
返回?你的意思是什么?这里没有返回啊?把代码给出来吧
如果你要以后修改strokeList就返回引用,否则就返回常值引用(这样速度快,只用传地址)
引用的语法就是:
type &var1 = var2;
比如int &a = b;
如果写成int &a = &b;就错了
虽然看起来是传值,其实编译器做了特殊处理,其实传的是地址
语法就是这样,不是什么原则
这句话声明一个pdoc->m_strokeList的一个引用strokeList,相当于给pdoc->m_strokeList另外起了个名字叫strokeList
它和下面代码是一样的:
int i;
int & nick_name_of_i =i;
Pcontext在那一页啊?
而你声明一个CTypedPtrList<CObList,CStroke*> 型的变量该有多大了?浪费空间
所以要用引用,当然指针也行
{
...
public:
UINT m_nPenWidth;
CDWordArray m_pointArray;
CRect m_rectBounding; // smallest rect that surrounds all
// of the points in the stroke
public:
CRect& GetBoundingRect() { return m_rectBounding; } ///////&??
void FinishStroke();
...
};”这里的“CRect& GetBoundingRect() { return m_rectBounding; }”如果写成“CRect GetBoundingRect() { return m_rectBounding; }”也是对的,等候Tranquillo(影子) 和ATField(field地回答...
但是函数GetBoundingRect() 的意图是要返回m_rectBounding的地址,便于通过地址对m_rectBounding本身进行操作,你返回一个副本,那么对返回值的操作不能影响到m_rectBounding本声,这样函数就失去了意义