Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Small fix for Find in Algo.h
icon13.gif  BUG for Find in Algo.h [message #34776 is a reply to message #20328] Mon, 12 December 2011 11:14 Go to previous messageGo to previous message
ratah is currently offline  ratah
Messages: 107
Registered: July 2010
Experienced Member
Hello,

I have a little bug when i use find algorithm. Here is my test :
#include <Core/Core.h>

using namespace Upp;

class CAppli:Moveable<CAppli>
{
	public:
		
		String m_appli;
                int m_count;
		
		CAppli(const String& appli)
		{
			m_appli = appli; m_count = 0;
		}
		
		String ToString()
		{
			String mycout;
			
			mycout << " APPLI : " << m_appli;
			
			return 	mycout;
		}

		void update()
		{
 		   m_count++;
		}
		
};

bool operator== (const CAppli& oAppli, const CAppli& oAppliTest)
{
	Cout() << "\n    -> test : " << oAppliTest.m_appli << " =? " << oAppli.m_appli;
		
 	if( oAppli.m_appli ==  oAppliTest.m_appli)
 	{
 		Cout() << "\n    -> result : " << oAppliTest.m_appli << " is equal to " << oAppli.m_appli;
 		return true;
 	}
 	else 
 	{
 		Cout() << "\n    -> result : " << oAppliTest.m_appli << " is different of " << oAppli.m_appli;
 		return false; 
 	}
}

class CJSON: public Json
{
	public :
	
		Vector<CAppli> vAppli;
		
		CJSON operator<< (const CAppli& oAppli)
		{
			Cout() << "\nTry to add " << oAppli.m_appli;
			
			Vector<CAppli>::Iterator it;
			it = Find(vAppli.Begin(), vAppli.End(), oAppli);
			
			if(it != vAppli.End())
			{			
				//CAppli apptmp = *it;              //<---- IT'S BUG !!!!!!!!
				//apptmp.update();
				//Cout() << "\n  <- Why I fall here even if " << apptmp.m_appli << " is different of " << oAppli.m_appli;
				
				Cout() << "\n  <- Why I fall here?";
			}			
			else
			{
				Cout() << " not yet in the vector. ";
				
				vAppli.Add(oAppli);
				Cout() << oAppli.m_appli << " added";
				
			}
			
			Cout() << "\n-----------\n\n";
			
			return (*this);
		}
};


CONSOLE_APP_MAIN
{
	CAppli appl1("APP1"), appl2("APP2"), appl3("APP3");
	
	CJSON ojson;	
	ojson << appl1 << appl2 << appl3 << appl2;
}


Thanks for your analyse and reply

Best regards,

Ratah

[Updated on: Mon, 12 December 2011 11:20]

Report message to a moderator

 
Read Message
Read Message
Read Message icon13.gif
Read Message
Read Message
Read Message
Previous Topic: A probably simple question about pick semantics
Next Topic: Preferred way to access VectorMap
Goto Forum:
  


Current Time: Tue May 14 21:40:07 CEST 2024

Total time taken to generate the page: 0.01679 seconds