Click here to Skip to main content
15,892,059 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generaldo{} while (0) Pin
flyingxu16-Mar-08 19:32
flyingxu16-Mar-08 19:32 
GeneralRe: do{} while (0) Pin
Maxwell Chen16-Mar-08 20:23
Maxwell Chen16-Mar-08 20:23 
GeneralRe: do{} while (0) Pin
BadKarma17-Mar-08 0:05
BadKarma17-Mar-08 0:05 
GeneralRe: do{} while (0) Pin
flyingxu17-Mar-08 15:30
flyingxu17-Mar-08 15:30 
QuestionBorland C++ Builder multiple forms problem Pin
Linardi16-Mar-08 19:29
Linardi16-Mar-08 19:29 
GeneralRe: Borland C++ Builder multiple forms problem Pin
Maxwell Chen16-Mar-08 20:30
Maxwell Chen16-Mar-08 20:30 
QuestionAbout p2p communication Pin
manish.patel16-Mar-08 19:16
manish.patel16-Mar-08 19:16 
Generalprecondition and post condition check Pin
George_George16-Mar-08 16:16
George_George16-Mar-08 16:16 
Hello everyone,


I am looking for a good sample about how to implement C++ pre-condition and post condition check, but can not find a good sample code. Do you have any referred ones? Smile | :)

Since I can not find, I wrote the patterns in two ways, I am not sure which is correct and if both are not correct, how to implement this pattern?

Sample code 1,

#define MAX 1024

class Base
{
public:
	void foo(int i)
	{
	if (i > MAX)
	{
		// error handling
	}
	else
	{
		do_foo(i);
	}
}

private:
	virtual void do_foo(int i) = 0;
};

class Derived : public Base
{
private:
	virtual void do_foo(int i)
	{
	// i is never > MAX here
	}
};

int main()
{
	Derived d;
	d.foo (1000);

	return 0;
}


Sample 2,

#define MAX 1024

class Base
{
public:
	void foo(int i)
	{
	if (i > MAX)
	{
		// error handling
	}
	else
	{
		do_foo(i);
	}
}

private:
	virtual void do_foo(int i) = 0;
};

class Derived : public Base
{
public:
	virtual void do_foo(int i)
	{
		foo (i);
		// i is never > MAX here
	}
};

int main()
{
	Derived d;
	d.do_foo (1000);

	return 0;
}



thanks in advance,
George
GeneralRe: precondition and post condition check Pin
Stephen Hewitt16-Mar-08 17:26
Stephen Hewitt16-Mar-08 17:26 
GeneralRe: precondition and post condition check Pin
George_George16-Mar-08 19:48
George_George16-Mar-08 19:48 
GeneralRe: precondition and post condition check Pin
Stephen Hewitt16-Mar-08 19:57
Stephen Hewitt16-Mar-08 19:57 
GeneralRe: precondition and post condition check Pin
George_George16-Mar-08 20:01
George_George16-Mar-08 20:01 
GeneralRe: precondition and post condition check Pin
Stephen Hewitt16-Mar-08 20:05
Stephen Hewitt16-Mar-08 20:05 
GeneralRe: precondition and post condition check Pin
George_George16-Mar-08 20:14
George_George16-Mar-08 20:14 
GeneralRe: precondition and post condition check Pin
Stephen Hewitt16-Mar-08 20:23
Stephen Hewitt16-Mar-08 20:23 
GeneralRe: precondition and post condition check Pin
George_George16-Mar-08 20:48
George_George16-Mar-08 20:48 
QuestionRe: precondition and post condition check Pin
CPallini16-Mar-08 22:59
mveCPallini16-Mar-08 22:59 
GeneralRe: precondition and post condition check Pin
Stephen Hewitt17-Mar-08 13:05
Stephen Hewitt17-Mar-08 13:05 
GeneralRe: precondition and post condition check Pin
CPallini17-Mar-08 22:07
mveCPallini17-Mar-08 22:07 
GeneralRe: precondition and post condition check Pin
CPallini16-Mar-08 22:38
mveCPallini16-Mar-08 22:38 
GeneralRe: precondition and post condition check Pin
George_George16-Mar-08 22:48
George_George16-Mar-08 22:48 
GeneralRe: precondition and post condition check Pin
CPallini16-Mar-08 22:50
mveCPallini16-Mar-08 22:50 
GeneralRe: precondition and post condition check Pin
George_George16-Mar-08 22:53
George_George16-Mar-08 22:53 
GeneralGeorge, again in the recursive trap Pin
CPallini17-Mar-08 22:11
mveCPallini17-Mar-08 22:11 
GeneralRe: George, again in the recursive trap Pin
George_George17-Mar-08 22:23
George_George17-Mar-08 22:23 

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.