Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Are there any lint-like guidelines for C++?

guidelines lint
0
10 Posted

Are there any lint-like guidelines for C++?

0

Yes, there are some practices which are generally considered dangerous. However none of these are universally “bad,” since situations arise when even the worst of these is needed: • A class Fred’s assignment operator should return *this as a Fred& (allows chaining of assignments) • A class with any virtual functions ought to have a virtual destructor • A class with any of {destructor, assignment operator, copy constructor} generally needs all 3 • A class Fred’s copy constructor and assignment operator should have const in the parameter: respectively Fred::Fred(const Fred&) and Fred& Fred::operator= (const Fred&) • When initializing an object’s member objects in the constructor, always use initialization lists rather than assignment. The performance difference for user-defined classes can be substantial (3x!) • Assignment operators should make sure that self assignment does nothing, otherwise you may have a disaster. In some cases, this may require you to add an explicit test to your as

0

Yes, there are some practices which are generally considered dangerous. However none of these are universally “bad,” since situations arise when even the worst of these is needed: • A class Fred’s assignment operator should return *this as a Fred& (allows chaining of assignments) • A class with any virtual functions ought to have a virtual destructor • A class with any of {destructor, assignment operator, copy constructor} generally needs all 3 • A class Fred’s copy constructor and assignment operator should have const in the parameter: respectively Fred::Fred(const Fred&) and Fred& Fred::operator= (const Fred&) • When initializing an object’s member objects in the constructor, always use initialization lists rather than assignment. The performance difference for user-defined classes can be substantial (3x!) • Assignment operators should make sure that self assignment does nothing, otherwise you may have a disaster. In some cases, this may require you to add an explicit test to your as

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.