-
March 19th, 2009, 10:40 AM
#1
Constructors
Whats the advantages of writing the constructor this way
CException( char* m ) { message = m; };
instead of the old fashion way?
Thanks
-
March 19th, 2009, 10:58 AM
#2
Re: Constructors
Be more descriptive.
By the way I'd use initialization list for constructing 'message' and I'd prefer string rather than char*. And I definitely don't know which is "the old fashion way".
-
March 19th, 2009, 11:10 AM
#3
Re: Constructors
Dont worry about the parameters, it was just an example, I describe it better this way:
This is one way:
CException( char* m ) { message = m; };
or other way I know is:
CException::CException(char *m)
{
message = m;
}
As i said ignore the actually parameters, its just the different ways of writing the constructor i am interested in.
Thanks
-
March 19th, 2009, 11:18 AM
#4
Re: Constructors
There is absolutely no difference whatsover in that case. You're just putting the same code on a different line.
This would be slightly different and generally better:
Code:
CException( char* m ): message(m)
{}
-
March 24th, 2009, 11:07 AM
#5
Re: Constructors
Hi;
Is there no advantage to it at all?
Just a handier way of writing it basically so?
Thanks
-
March 24th, 2009, 11:19 AM
#6
Re: Constructors
Originally Posted by newbie30
Hi;
Is there no advantage to it at all?
Just a handier way of writing it basically so?
Thanks
It's EXACTLY the same code. All you did was put the braces and statement on one line, which IMHO is a bad habit as it makes code harder to read and debug.
-
March 24th, 2009, 11:20 AM
#7
Re: Constructors
I suppose declaring it inline in the class might make the compiler more likely to inline the function, same as any class routine. But otherwise it doesn't matter.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|