Click here to Skip to main content
15,847,077 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: User interface problem -- check a point is inside a polygon or not [modified] Pin
George_George1-Jun-06 22:50
George_George1-Jun-06 22:50 
GeneralRe: User interface problem -- check a point is inside a polygon or not [modified] Pin
Cedric Moonen1-Jun-06 22:57
Cedric Moonen1-Jun-06 22:57 
GeneralRe: User interface problem -- check a point is inside a polygon or not [modified] Pin
George_George1-Jun-06 23:09
George_George1-Jun-06 23:09 
GeneralRe: User interface problem -- check a point is inside a polygon or not [modified] Pin
Stephen Hewitt1-Jun-06 23:10
Stephen Hewitt1-Jun-06 23:10 
GeneralRe: User interface problem -- check a point is inside a polygon or not [modified] Pin
George_George1-Jun-06 23:32
George_George1-Jun-06 23:32 
Questionsorting vector that holds object Pin
voorugonda prashanth1-Jun-06 21:49
voorugonda prashanth1-Jun-06 21:49 
AnswerRe: sorting vector that holds object Pin
Stephen Hewitt1-Jun-06 22:13
Stephen Hewitt1-Jun-06 22:13 
AnswerRe: sorting vector that holds object [modified] Pin
Viorel.1-Jun-06 22:29
Viorel.1-Jun-06 22:29 
If you talk about STL library, then the sorting can be done with sort function defined in algorithm. You have to devine a "binary predicate", wich compares objects according to your needs. Solution depends on how you store objects in vector -- as values or as pointers. The bellow sample shows both cases:

struct MyObject
{
	MyObject(int x, int y)
	{
		mX = x; mY = y;
	}

	// binary predicate for the case of storing values
	static bool ComparatorByX_values(const MyObject & obj1, const MyObject & obj2)
	{
		return obj1.mX < obj2.mY;
	}

	// binary predicate for the case of storing pointers
	static bool ComparatorByX_pointers(const MyObject * obj1, const MyObject * obj2)
	{
		return obj1->mX < obj2->mY;
	}

	int mX, mY;
};


int main()
{
	{
		// case 1: storing values.

		std::vector< MyObject > vector;

		vector.push_back(MyObject(3, 20));
		vector.push_back(MyObject(2, 10));
		vector.push_back(MyObject(1, 30));

		// sort by X
		std::sort(vector.begin(), vector.end(), MyObject::ComparatorByX_values);

		// print X
		for(size_t i = 0; i < vector.size(); ++i)
		{
			printf("%i\n", vector[i].mX);
		}
	}

	{
		// case 2: storing pointers.

		std::vector< MyObject * > vector;

		vector.push_back(new MyObject(3, 20));
		vector.push_back(new MyObject(2, 10));
		vector.push_back(new MyObject(1, 30));

		// sort by X
		std::sort(vector.begin(), vector.end(), MyObject::ComparatorByX_pointers);

		for(size_t i = 0; i < vector.size(); ++i)
		{
			printf("%i\n", vector[i]->mX);
		}

		// (TODO: delete the objects using "delete" in a loop)

	}
}


Hope this will ispire you.


-- modified at 10:46 Friday 2nd June, 2006
AnswerRe: sorting vector that holds object Pin
toxcct1-Jun-06 22:54
toxcct1-Jun-06 22:54 
QuestionHow to draw line graph without using MsExcel Pin
MikeRT1-Jun-06 21:39
MikeRT1-Jun-06 21:39 
AnswerRe: How to draw line graph without using MsExcel Pin
Cedric Moonen1-Jun-06 22:09
Cedric Moonen1-Jun-06 22:09 
QuestionIcon added to system trat but popup menu not disappear if I click somewhere else Pin
zahid_ash1-Jun-06 21:38
zahid_ash1-Jun-06 21:38 
AnswerRe: Icon added to system trat but popup menu not disappear if I click somewhere else Pin
Hamid_RT1-Jun-06 21:47
Hamid_RT1-Jun-06 21:47 
GeneralRe: used the same one but popup menu not disappear if I click on some other window Pin
zahid_ash1-Jun-06 21:54
zahid_ash1-Jun-06 21:54 
AnswerRe: Icon added to system trat but popup menu not disappear if I click somewhere else [modified] Pin
Viorel.1-Jun-06 22:52
Viorel.1-Jun-06 22:52 
Questionprogram executing error Pin
Y_Kaushik1-Jun-06 21:31
Y_Kaushik1-Jun-06 21:31 
AnswerRe: program executing error Pin
_AnsHUMAN_ 1-Jun-06 21:37
_AnsHUMAN_ 1-Jun-06 21:37 
AnswerRe: program executing error Pin
toxcct1-Jun-06 22:50
toxcct1-Jun-06 22:50 
QuestionFFMPEG(Libavcodec DLL)+VC++ Pin
RahulOP1-Jun-06 21:29
RahulOP1-Jun-06 21:29 
AnswerRe: FFMPEG(Libavcodec DLL)+VC++ Pin
Hamid_RT1-Jun-06 21:37
Hamid_RT1-Jun-06 21:37 
GeneralRe: FFMPEG(Libavcodec DLL)+VC++ Pin
RahulOP1-Jun-06 22:08
RahulOP1-Jun-06 22:08 
GeneralRe: FFMPEG(Libavcodec DLL)+VC++ Pin
Hamid_RT1-Jun-06 22:31
Hamid_RT1-Jun-06 22:31 
GeneralRe: FFMPEG(Libavcodec DLL)+VC++ [modified] Pin
RahulOP1-Jun-06 23:43
RahulOP1-Jun-06 23:43 
GeneralRe: FFMPEG(Libavcodec DLL)+VC++ [modified] Pin
Hamid_RT2-Jun-06 2:10
Hamid_RT2-Jun-06 2:10 
GeneralRe: FFMPEG(Libavcodec DLL)+VC++ [modified] Pin
RahulOP4-Jun-06 19:36
RahulOP4-Jun-06 19:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.