1 Replies - 325 Views - Last Post: 28 January 2013 - 06:28 AM Rate Topic: -----

#1 jhomers  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-January 13

Question about operator overloading

Posted 27 January 2013 - 11:15 PM

Hello,

I have a question about a particular code inside the overloading function where the variable BOOL bOk = operator << (dwSize);. I would just like to know how it actually work and changes does this statement do.

Here is the full code:
template<typename TYPE>
BOOL bRoom::operator >> ( std::vector<TYPE> &stdVALUE )
{
	BOOL bOK(FALSE);
	DWORD dwSize(0);

	stdVALUE.clear();

	bOK = operator >> ( dwSize );
	if ( !bOK )					return FALSE;
	
	if ( dwSize==0 )			return TRUE;

	stdVALUE.reserve(dwSize);

	return TRUE;
}



I'm not sure if there is somebody that have already posted that here as I don't have any idea what it is called and do. If there is a name for that particular statement, I would love to know it.

Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Question about operator overloading

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4074
  • View blog
  • Posts: 12,568
  • Joined: 25-December 09

Re: Question about operator overloading

Posted 28 January 2013 - 06:28 AM

Please explain exactly what you are trying to do with this function. The function as written doesn't actually make much sense. Why would you try to overload the extraction operator (operator>>) to clear() your vector? Normally you use the extraction operator>> to add items to your data structure. Also an overloaded extraction operator should not be returning a bool, it should be returning a stream reference.

Second the word "operator" is a C++ keyword and is only used when declaring a function to overload the operator in question, in this case the extraction operator. This means that the following line is malformed:
bOK = operator >> ( dwSize );


You may want to read up a little about overloading the I/O operators.

Jim

This post has been edited by jimblumberg: 28 January 2013 - 06:31 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1