Constructors...in the header or cpp file?
What''s the difference between defining the implementation of a constructor in a header or cpp file?
quote:Original post by Agape
What''s the difference between defining the implementation of a constructor in a header or cpp file?
Readability and consistancy.
quote:Original post by Agape
What''s the difference between defining the implementation of a constructor in a header or cpp file?
What''s the difference between defining the implementation of ANY function in a header or cpp file?
if defined inside class => unreadable
outside class but in .h => link errors (with more than one .cpp refering to the class which often occurs)
in .cpp => readable, no recompilation, no errors.. perfect
outside class but in .h => link errors (with more than one .cpp refering to the class which often occurs)
in .cpp => readable, no recompilation, no errors.. perfect
If the method is only a return statment, I define the method inline i.e. in the .h file:
That's the only time it simpifies code reading, I think.
[edited by - Enselic on October 14, 2003 10:09:11 AM]
float getSpeed() const { return _fSpeed; }
That's the only time it simpifies code reading, I think.
[edited by - Enselic on October 14, 2003 10:09:11 AM]
quote:Original post by deathtrap
Any class methods declared and defined in the header file is implicitly made inline.
Unless they''re not.
Putting the implementation in the header file creates unnecessary dependencies between classes. Keep the header file limited to interface, and put the implementation in the .cpp file. Do a Google search on "pimpl idiom" for a preferred way to do this.
--
Dave Mikesell
d.mikesell@computer.org
http://davemikesell.com
--
Dave Mikesell
d.mikesell@computer.org
http://davemikesell.com
quote:Original post by dmikesell
Putting the implementation in the header file creates unnecessary dependencies between classes. Keep the header file limited to interface, and put the implementation in the .cpp file. Do a Google search on "pimpl idiom" for a preferred way to do this.
--
Dave Mikesell
d.mikesell@computer.org
http://davemikesell.com
Even in my case? In what way does it become unnucessary dependencies?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement