ChinaUnix.net
相关文章推荐:

c const 重载

我的类有这三个方法: inline context& operator =(const context& _xctx){this->assign(_xctx.getAll());return *this;} //1 void assign(const map _mp); //2 map getAll(){return mp;} //3 private: map _xctx; 其中方法1在编译时报: The non-const member function "context::getAll()" is called for "const context" 好像是说 getAll是非const方法,被方法1调用了。...

by jchc - C/C++ - 2008-09-25 14:04:54 阅读(3826) 回复(11)

相关讨论

c++中重载操作符的时候,如String类的加方法的定义:String & operator= (const String &); 如我想定义另外一个操作符,参数确定规则是什么?谢谢!

by winter_huang - C/C++ - 2006-10-12 08:57:26 阅读(1097) 回复(2)
by 版_主 - C/C++ - 2009-07-07 22:08:48 阅读(4647) 回复(13)

请教下下,最好 有代码来区别他们.谢谢

by guhan010 - C/C++ - 2007-10-29 11:48:48 阅读(1805) 回复(2)

运算符重载(operator overloading)只是一种“语法上的方便”,也就是说它只是另一种函数调用的方式。 --c++编程思想 所以调用这些“函数”时,就要...

by zwylinux - C/C++ - 2007-08-24 12:26:41 阅读(1479) 回复(0)

如果基类中有一个private成员,如何在派生类中重载“=”, 使派生类的对象之间赋值,基类中的private成员也能被赋值

by icw_zy - C/C++ - 2007-08-10 12:06:55 阅读(2582) 回复(7)

下面的“=”函数重载是错的,但只要把string operator=(const string s )改成string &operator=(const string &s )就对了。想不通为什么非要加&。 #include ; #include ; // using namespace std; class string { char *ptr; public: string(char *s) { ptr=new char[strlen(s)+1]; strcpy(ptr,s); } ~string() { delete ptr; } void print() ...

by catmonkey_lee - C/C++ - 2004-11-08 09:38:04 阅读(3284) 回复(22)

int func(void) const; /* 函数本身是常量,即只读函数 */ 在网上搜的,但仅此一句,不懂(仅解释一句) 我想问一下,这个函数与其他非 const 函数有什么区别? c 中有这种语法吗?我知 c++中用法是只能处理常量,不知 c 是不是? [ 本帖最后由 izhier 于 2008-11-1 16:00 编辑 ]

by izhier - C/C++ - 2008-11-03 19:44:45 阅读(3588) 回复(8)

solaris8系统 .cc文件中 const int x=20; int *y=& 有错误么? c++ core书上说是syntax error可是我cc通过 我用的是FORTEc++4.2,可编译器问题,还是 操作系统认为这是正确的 请大虾指教!

by bsj2100a - Solaris - 2003-10-15 09:01:21 阅读(653) 回复(0)

solaris8系统 .cc文件中 const int x=20; int *y=& 有错误么? c++ core书上说是syntax error可是我cc通过 我用的是FORTEc++4.2,可编译器问题,还是 操作系统认为这是正确的 请大虾指教!

by bsj2100a - C/C++ - 2003-10-15 12:01:23 阅读(882) 回复(2)

extern void func(void);//该函数的实践在lib中 我想做到实现自己的 void func(void) { func();//调用lib中的func do_others(); }

by FreeGnu - C/C++ - 2009-05-12 14:23:10 阅读(2233) 回复(15)