Sponsored Content
Top Forums Programming C++ operator overloading error Post 303026998 by Corona688 on Thursday 6th of December 2018 04:19:25 PM
Old 12-06-2018
Returning rside is clever and ought to work, but return-by-value is a bad idea -- that makes a local copy, which isn't just wasteful, in some circumstances that's an infinite recursion and out-of-memory crash. Assignment operators shouldn't use copy constructors.

You pretty much have to return a reference here.

Code:
const myString &operator=(const myString& rside)

This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. AIX

xlC compilation error when dealing with operator overloading

Hi, I have a piece of C++ code that can be compiled using g++, but reports an error when compiled with xlC: xlC -DHAVE_CONFIG_H -I../SRC -I../include -DNoChange -DSPRNG_MPI -q64 -DLONG64=long -I/usr/lpp/ppe.poe/include -DLONG64=long -c -o libsprng_a-bignum.o bignum.cpp "bignum.cpp",... (1 Reply)
Discussion started by: luop0812
1 Replies

2. UNIX for Dummies Questions & Answers

unary operator expected error

Hi I am doing a script like if then echo "table name dosent exist" exit fi the problem is if $table_name is null then i am getting the error Please help me Thanks in advance (2 Replies)
Discussion started by: ssuresh1999
2 Replies

3. Programming

C++ Optr Overloading

Hi All, In C++ one operator can be overloaded, but it can't be overloaded by it's own derieved class Please let me know operator. Thanks, Naga:cool: (1 Reply)
Discussion started by: Nagapandi
1 Replies

4. UNIX for Dummies Questions & Answers

File already exists error while using '>' operator

hi i am using the below code grep -v '^$' file1.lst >file1.lst but it gives file1.lst already exists. And i want to over rite on the same file Whats the work around? (5 Replies)
Discussion started by: jathin12
5 Replies

5. UNIX for Dummies Questions & Answers

Error : -ne: unary operator expected

find . -name "*.*"|xargs grep WT:DBF_WL>> $F Wfexist=`cat $F|grep $i` echo $Wfexist if ; then echo $Wfexist echo "Workflow Exist" else touch $O chmod 777 $O echo $Wfexist echo $WfExist >> $O fi I am getting the error that -ne: unary operator expected in the line with red... (2 Replies)
Discussion started by: ritu.s
2 Replies

6. Programming

Delete operator overloading with multiple arguments.

Hi, I have an requirement to overload the delete operator in C++, but it should also accept the sizeof() the object that is to be deleted. Actually I am trying to built a custom memory allocator and deallocator like a pool, which makes me to overload the delete operator. Small example of the... (1 Reply)
Discussion started by: kapilkumawat
1 Replies

7. UNIX for Dummies Questions & Answers

[: =: unary operator expected error

Why am I getting this error.... #!/bin/sh # iOS-Ad-Remover # Marshall Ford @ marshallbford@gmail.com # This project is hosted @ http://ios-ad- # remover.sourceforge.net # Under the GNU GPL open source license clear echo if ; then echo "You need to be root to run this script."; exit 0; #... (24 Replies)
Discussion started by: mbf123
24 Replies

8. Programming

c++ assignment operator overloading

Hello everyone! Suppose that I have something like this A a; a.mem=new int; A b = a; where class A { public: int * mem; A() : mem(NULL) { } ~A() { if (mem!=NULL) delete mem; (1 Reply)
Discussion started by: bashuser2
1 Replies

9. UNIX for Dummies Questions & Answers

mysqld overloading cpu of VPS

Hi bros I have a VPS 512mb (Burst 2GB) with Kloxo installed and hosting few sites on it with not much traffic I am facing high cpu load for the last few days and seems mysqld is overloading the cpu Any suggestion will be appreciated Regards Rizwan Top output is as under top -... (2 Replies)
Discussion started by: rizwan65
2 Replies

10. Shell Programming and Scripting

Help - binary operator expected error

Hello Unix forum. I'm encountering the following error "binary operator expected error" and I cannot seem to solve the issue. I have the following source files to process: CPA_LOOKUP_dat.lst PROFILE_TXN__dat.lst TRANSACTION_CODE_dat.lst PROFILE_TXN_OUT_OF_BALANCE_dat.lst ... (2 Replies)
Discussion started by: pchang
2 Replies
QBitArray(3qt)															    QBitArray(3qt)

NAME
QBitArray - Array of bits SYNOPSIS
All the functions in this class are reentrant when Qt is built with thread support.</p> #include <qbitarray.h> Inherits QByteArray. Public Members QBitArray () QBitArray ( uint size ) QBitArray ( const QBitArray & a ) QBitArray & operator= ( const QBitArray & a ) uint size () const bool resize ( uint size ) bool fill ( bool v, int size = -1 ) virtual void detach () QBitArray copy () const bool testBit ( uint index ) const void setBit ( uint index ) void setBit ( uint index, bool value ) void clearBit ( uint index ) bool toggleBit ( uint index ) bool at ( uint index ) const QBitVal operator[] ( int index ) bool operator[] ( int index ) const QBitArray & operator&= ( const QBitArray & a ) QBitArray & operator|= ( const QBitArray & a ) QBitArray & operator^= ( const QBitArray & a ) QBitArray operator~ () const RELATED FUNCTION DOCUMENTATION
QBitArray operator& ( const QBitArray & a1, const QBitArray & a2 ) QBitArray operator| ( const QBitArray & a1, const QBitArray & a2 ) QBitArray operator^ ( const QBitArray & a1, const QBitArray & a2 ) QDataStream & operator<< ( QDataStream & s, const QBitArray & a ) QDataStream & operator>> ( QDataStream & s, QBitArray & a ) DESCRIPTION
The QBitArray class provides an array of bits. Because QBitArray is a QMemArray, it uses explicit sharing with a reference count. A QBitArray is a special byte array that can access individual bits and perform bit-operations (AND, OR, XOR and NOT) on entire arrays or bits. Bits can be manipulated by the setBit() and clearBit() functions, but it is also possible to use the indexing [] operator to test and set individual bits. The [] operator is a little slower than setBit() and clearBit() because some tricks are required to implement single-bit assignments. Example: QBitArray a(3); a.setBit( 0 ); a.clearBit( 1 ); a.setBit( 2 ); // a = [1 0 1] QBitArray b(3); b[0] = 1; b[1] = 1; b[2] = 0; // b = [1 1 0] QBitArray c; c = ~a & b; // c = [0 1 0] When a QBitArray is constructed the bits are uninitialized. Use fill() to set all the bits to 0 or 1. The array can be resized with resize() and copied with copy(). Bits can be set with setBit() and cleared with clearBit(). Bits can be toggled with toggleBit(). A bit's value can be obtained with testBit() and with at(). QBitArray supports the & (AND), | (OR), ^ (XOR) and ~ (NOT) operators. See also Collection Classes, Implicitly and Explicitly Shared Classes, and Non-GUI Classes. MEMBER FUNCTION DOCUMENTATION
QBitArray::QBitArray () Constructs an empty bit array. QBitArray::QBitArray ( uint size ) Constructs a bit array of size bits. The bits are uninitialized. See also fill(). QBitArray::QBitArray ( const QBitArray & a ) Constructs a shallow copy of a. bool QBitArray::at ( uint index ) const Returns the value (0 or 1) of the bit at position index. See also operator[](). void QBitArray::clearBit ( uint index ) Clears the bit at position index, i.e. sets it to 0. See also setBit() and toggleBit(). QBitArray QBitArray::copy () const Returns a deep copy of the bit array. See also detach(). void QBitArray::detach () [virtual] Detaches from shared bit array data and makes sure that this bit array is the only one referring to the data. If multiple bit arrays share common data, this bit array dereferences the data and gets a copy of the data. Nothing happens if there is only a single reference. See also copy(). Reimplemented from QMemArray. bool QBitArray::fill ( bool v, int size = -1 ) Fills the bit array with v (1's if v is TRUE, or 0's if v is FALSE). fill() resizes the bit array to size bits if size is nonnegative. Returns FALSE if a nonnegative size was specified and the bit array could not be resized; otherwise returns TRUE. See also resize(). QBitArray &; QBitArray::operator&= ( const QBitArray & a ) Performs the AND operation between all bits in this bit array and a. Returns a reference to this bit array. The result has the length of the longest of the two bit arrays, with any missing bits (i.e. if one array is shorter than the other), taken to be 0. QBitArray a( 3 ), b( 2 ); a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1] b[0] = 1; b[1] = 0; // b = [1 0] a &= b; // a = [1 0 0] See also operator|=(), operator^=(), and operator~(). QBitArray &; QBitArray::operator= ( const QBitArray & a ) Assigns a shallow copy of a to this bit array and returns a reference to this array. QBitVal QBitArray::operator[] ( int index ) Implements the [] operator for bit arrays. The returned QBitVal is a context object. It makes it possible to get and set a single bit value by its index position. Example: QBitArray a( 3 ); a[0] = 0; a[1] = 1; a[2] = a[0] ^ a[1]; The functions testBit(), setBit() and clearBit() are faster. See also at(). bool QBitArray::operator[] ( int index ) const This is an overloaded member function, provided for convenience. It behaves essentially like the above function. Implements the [] operator for constant bit arrays. QBitArray &; QBitArray::operator^= ( const QBitArray & a ) Performs the XOR operation between all bits in this bit array and a. Returns a reference to this bit array. The result has the length of the longest of the two bit arrays, with any missing bits (i.e. if one array is shorter than the other), taken to be 0. QBitArray a( 3 ), b( 2 ); a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1] b[0] = 1; b[1] = 0; // b = [1 0] a ^= b; // a = [0 0 1] See also operator&=(), operator|=(), and operator~(). QBitArray &; QBitArray::operator|= ( const QBitArray & a ) Performs the OR operation between all bits in this bit array and a. Returns a reference to this bit array. The result has the length of the longest of the two bit arrays, with any missing bits (i.e. if one array is shorter than the other), taken to be 0. QBitArray a( 3 ), b( 2 ); a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1] b[0] = 1; b[1] = 0; // b = [1 0] a |= b; // a = [1 0 1] See also operator&=(), operator^=(), and operator~(). QBitArray QBitArray::operator~ () const Returns a bit array that contains the inverted bits of this bit array. Example: QBitArray a( 3 ), b; a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1] b = ~a; // b = [0 1 0] bool QBitArray::resize ( uint size ) Resizes the bit array to size bits and returns TRUE if the bit array could be resized; otherwise returns FALSE. The array becomes a null array if size == 0. If the array is expanded, the new bits are set to 0. See also size(). void QBitArray::setBit ( uint index, bool value ) Sets the bit at position index to value. Equivalent to: if ( value ) setBit( index ); else clearBit( index ); See also clearBit() and toggleBit(). void QBitArray::setBit ( uint index ) This is an overloaded member function, provided for convenience. It behaves essentially like the above function. Sets the bit at position index to 1. See also clearBit() and toggleBit(). uint QBitArray::size () const Returns the bit array's size (number of bits). See also resize(). bool QBitArray::testBit ( uint index ) const Returns TRUE if the bit at position index is set, i.e. is 1; otherwise returns FALSE. See also setBit() and clearBit(). bool QBitArray::toggleBit ( uint index ) Toggles the bit at position index. If the previous value was 0, the new value will be 1. If the previous value was 1, the new value will be 0. See also setBit() and clearBit(). RELATED FUNCTION DOCUMENTATION
QBitArray operator&; ( const QBitArray & a1, const QBitArray & a2 ) Returns the AND result between the bit arrays a1 and a2. The result has the length of the longest of the two bit arrays, with any missing bits (i.e. if one array is shorter than the other), taken to be 0. See also QBitArray::operator&=(). QDataStream &; operator<< ( QDataStream & s, const QBitArray & a ) Writes bit array a to stream s. See also Format of the QDataStream operators. QDataStream &; operator>> ( QDataStream & s, QBitArray & a ) Reads a bit array into a from stream s. See also Format of the QDataStream operators. QBitArray operator^ ( const QBitArray & a1, const QBitArray & a2 ) Returns the XOR result between the bit arrays a1 and a2. The result has the length of the longest of the two bit arrays, with any missing bits (i.e. if one array is shorter than the other), taken to be 0. See also QBitArray::operator^(). QBitArray operator| ( const QBitArray & a1, const QBitArray & a2 ) Returns the OR result between the bit arrays a1 and a2. The result has the length of the longest of the two bit arrays, with any missing bits (i.e. if one array is shorter than the other), taken to be 0. See also QBitArray::operator|=(). SEE ALSO
http://doc.trolltech.com/qbitarray.html http://www.trolltech.com/faq/tech.html COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. AUTHOR
Generated automatically from the source code. BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qbitarray.3qt) and the Qt version (3.1.1). Trolltech AS 9 December 2002 QBitArray(3qt)
All times are GMT -4. The time now is 02:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy