ChinaUnix.net
相关文章推荐:

赋值操作的重载

c++ primer plus 上有这样一段代码 Time operator*(double m,const Time &t) { return t * m; } 这里不将这个函数声明为友元 编译器报告说operator *' has too many parameters 是不是书上错了呀

by di00di - C/C++ - 2012-08-07 16:35:03 阅读(1192) 回复(4)

相关讨论

类的重载操作符+ 和+= 比如有个类A A operator +(const A& lhs,const A& rhs) { A ret=lhs; ret+=rhs; //这里 return ret; } A& operator+=(A & rhs) { (*this)=(*this)+rhs;//跟这里 return (*this); } 让操作符怎么来认识这个自定义的类 用+操作符需要用到的是+=操作符 用+=操作符又返回来用的是+操作符 该怎么做才能正确的重载这个类操作

by kingjo47 - C/C++ - 2012-06-14 13:05:48 阅读(1297) 回复(4)

本帖最后由 getmonyinfo 于 2012-03-08 20:35 编辑 为[code]ssize_t write(int fd, const void *buf, size_t count);[/code]函数写了一个buffer类, 代码如下:[code] #include #include #include #include #include using namespace std; class Buffer { public: Buffer (); Buffer (size_t size); ~Buffer () { if (Data != NULL) free( Data); } size_t ...

by getmonyinfo - C/C++ - 2012-03-09 10:17:57 阅读(2219) 回复(15)

在读gtest-1.6.0的源码时,看到一个操作重载的句子,如下[code] // Returns true iff the assertion succeeded. operator bool() const { return success_; } // NOLINT[/code]这是什么语法,上述句子和下面这个有区别吗?[code] bool operator() const{ return success_; } [/code]

operatoroverload

by sudayly - C/C++ - 2011-10-03 18:47:30 阅读(1787) 回复(1)

[code] class Date{ int month; int day; int year; int hour; int minute; int second; // and the get set function } // the iostream // format: mm/dd/yyyy hh:mm:ss \n //mm/dd/yyyy hh:nn:ss \n ostream &operator<<(ostream& out, const Date& date){ out << date.getMonth() << "/" << date.getDay() << "/" << date.getYear() << " " << date.getHour() << ":" << date.getMinute() << ":" ...

by DraculaW - C/C++ - 2007-01-10 14:53:48 阅读(923) 回复(2)

请问这个代码中: #include #include class string{ char *ptr; public: string (char *s) {ptr=new char[strlen(s)+1]; strcpy(ptr,s); } ~string() {delete ptr;} void print() {cout<

by xnec - C/C++ - 2007-01-07 14:02:09 阅读(855) 回复(4)

[code] class CMemDC{ operator CMemDC*() /*这种操作重载,该怎么调用?*/ { return this; } } 为什么不是这样重载 CMemDC operator *() { return this; } [/code]

by mabuc - C/C++ - 2009-05-18 16:30:19 阅读(1288) 回复(9)

例子代码如下: template class A { private: ...... protected: ...... public: ...... virtual T & operator[](int i); virtual T operator[](int i)const; ....... }; 我在好多代码中看到如上例子程序中对[]符号的重载都有不同的2种,我感觉好象没必要有2种把,请大家帮我看下,为什么需要2种呢,这2种有什么区别呢,请大家帮我解释下,谢谢。。

by fanzhijie875151 - C/C++ - 2008-07-25 16:59:27 阅读(1195) 回复(2)

哪里有tut之类的? 或者哪位给俺们讲讲?

by adamz - Perl - 2008-01-11 12:32:52 阅读(2057) 回复(2)

如题,python已经支持了许多运算符重载,但不知道是否支持=重载呢?

by kgd7558 - Python - 2009-09-06 10:29:39 阅读(3915) 回复(2)

我写了这样一个脚本 echo -n "Please set the full path of oracle installation package:" read full #设置文件解压的输出目录,默认为安装包所在目录 echo -n "Please set output directory:" read output echo $full echo $output 7z x $full -o$output 当我执行这个脚本的时候,第一个参数输入的是"/root/Oracle Database 10.2.0.1.0.zip" 第二个是/var 但是执行后提示 7-Zip (A) 4.58 beta Copyright (c) 1999-2008 ...

by 撒加 - Shell - 2009-11-30 15:49:18 阅读(2344) 回复(13)