By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,127 Members | 1,211 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,127 IT Pros & Developers. It's quick & easy.

reg. constructor parameters

P: n/a
Hi all,

I have these classes (for a GUI library) that uses
alot of variables that need to be set at c-tor time

i.e.

class Button : Widget {
public:
Button (int x, int y) : Widget (BUTTON),
m_x (x),
m_y (y),
name (""),
etc /.../

Is it true that this generates better (meaning faster)
code than doing this?

Button (int x, int y) {
this->m_x = x;
this->m_y = y;
etc /.../

Thanks.

-- Pelle
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Pelle Beckman wrote:
I have these classes (for a GUI library) that uses
alot of variables that need to be set at c-tor time

i.e.

class Button : Widget {
public:
Button (int x, int y) : Widget (BUTTON),
m_x (x),
m_y (y),
name (""),
etc /.../

Is it true that this generates better (meaning faster)
code than doing this?

Button (int x, int y) {
this->m_x = x;
this->m_y = y;
etc /.../


Generally speaking, yes. Please refer to FAQ. Search for "assignment
initialization".

V
Jul 23 '05 #2

P: n/a
Pelle Beckman wrote:
Hi all,

I have these classes (for a GUI library) that uses
alot of variables that need to be set at c-tor time

i.e.

class Button : Widget {
public:
Button (int x, int y) : Widget (BUTTON),
m_x (x),
m_y (y),
name (""),
etc /.../

Is it true that this generates better (meaning faster)
code than doing this?

Button (int x, int y) {
this->m_x = x;
this->m_y = y;
etc /.../

Thanks.

-- Pelle


Yes almost always but there is just 1 exception to the rule. Pls go
through
http://www.parashift.com/c++-faq-lit....html#faq-10.6

Jul 23 '05 #3

P: n/a
> Yes almost always but there is just 1 exception to the rule. Pls go
through
http://www.parashift.com/c++-faq-lit....html#faq-10.6


Hi, is there any effect in applying this when having virtual
inheritance.

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.