Skip to main content
Commonmark migration
Source Link

##This code must NOT compile!

This code must NOT compile!

##0th Solution: the basic interface

0th Solution: the basic interface

##1st Solution: boost::noncopyable

1st Solution: boost::noncopyable

##2nd Solution: make them protected!

2nd Solution: make them protected!

##Conclusion

Conclusion

##Bounty and results

Bounty and results

##This code must NOT compile!

##0th Solution: the basic interface

##1st Solution: boost::noncopyable

##2nd Solution: make them protected!

##Conclusion

##Bounty and results

This code must NOT compile!

0th Solution: the basic interface

1st Solution: boost::noncopyable

2nd Solution: make them protected!

Conclusion

Bounty and results

now derived classes isn't constrainted from default compiler generated move operations
Source Link
class MyInterface { public : virtual ~MyInterface() {} protected : // With C++11, these methods would be "= default" MyInterface() {} MyInterface(const MyInterface & ) {} MyInterface & operator = (const MyInterface & ) { return *this ; }  MyInterface(MyInterface && ) noexcept {} MyInterface & operator = (MyInterface && ) noexcept { return *this ; } } ; 
#define DECLARE_CLASS_AS_INTERFACE(ClassName) \ public : \ virtual ~ClassName() {} \ protected : \ ClassName() {} \ ClassName(const ClassName & ) {} \ ClassName & operator = (const ClassName & ) { return *this ; } \   ClassName(ClassName && ) noexcept {} \ ClassName & operator = (ClassName && ) noexcept { return *this ; } \ private : 
  • This class cannot be instantiated (the constructors are protected)
  • This class can be virtually destroyed
  • This class can be inherited without imposing undue constraints on inheriting classes (e.g. the inheriting class could be by default copiable/moveable)
  • The use of the macro means the interface "declaration" is easily recognizable (and searchable), and its code is factored in one place making it easier to modify (a suitably prefixed name will remove undesirable name clashes)
class MyInterface { public : virtual ~MyInterface() {} protected : // With C++11, these methods would be "= default" MyInterface() {} MyInterface(const MyInterface & ) {} MyInterface & operator = (const MyInterface & ) { return *this ; } } ; 
#define DECLARE_CLASS_AS_INTERFACE(ClassName) \ public : \ virtual ~ClassName() {} \ protected : \ ClassName() {} \ ClassName(const ClassName & ) {} \ ClassName & operator = (const ClassName & ) { return *this ; } \ private : 
  • This class cannot be instantiated (the constructors are protected)
  • This class can be virtually destroyed
  • This class can be inherited without imposing undue constraints on inheriting classes (e.g. the inheriting class could be by default copiable)
  • The use of the macro means the interface "declaration" is easily recognizable (and searchable), and its code is factored in one place making it easier to modify (a suitably prefixed name will remove undesirable name clashes)
class MyInterface { public : virtual ~MyInterface() {} protected : // With C++11, these methods would be "= default" MyInterface() {} MyInterface(const MyInterface & ) {} MyInterface & operator = (const MyInterface & ) { return *this ; }  MyInterface(MyInterface && ) noexcept {} MyInterface & operator = (MyInterface && ) noexcept { return *this ; } } ; 
#define DECLARE_CLASS_AS_INTERFACE(ClassName) \ public : \ virtual ~ClassName() {} \ protected : \ ClassName() {} \ ClassName(const ClassName & ) {} \ ClassName & operator = (const ClassName & ) { return *this ; } \   ClassName(ClassName && ) noexcept {} \ ClassName & operator = (ClassName && ) noexcept { return *this ; } \ private : 
  • This class cannot be instantiated (the constructors are protected)
  • This class can be virtually destroyed
  • This class can be inherited without imposing undue constraints on inheriting classes (e.g. the inheriting class could be by default copiable/moveable)
  • The use of the macro means the interface "declaration" is easily recognizable (and searchable), and its code is factored in one place making it easier to modify (a suitably prefixed name will remove undesirable name clashes)
replaced https://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
Source Link

I awarded the bounty to coredumpcoredump because of the time spent to answer the questions, and the relevance of the answers.

I awarded the bounty to coredump because of the time spent to answer the questions, and the relevance of the answers.

I awarded the bounty to coredump because of the time spent to answer the questions, and the relevance of the answers.

code correction
Source Link
paercebal
  • 1.5k
  • 1
  • 12
  • 17
Loading
Conclusions
Source Link
paercebal
  • 1.5k
  • 1
  • 12
  • 17
Loading
Notice removed Draw attention by paercebal
Bounty Ended with coredump's answer chosen by paercebal
Tweeted twitter.com/#!/StackProgrammer/status/455667762711760896
Notice added Draw attention by paercebal
Bounty Started worth 300 reputation by paercebal
deleted 91 characters in body
Source Link
Thomas Owens
  • 85.9k
  • 18
  • 211
  • 311
Loading
Post Migrated Here from codereview.stackexchange.com (revisions)
Source Link
paercebal
  • 1.5k
  • 1
  • 12
  • 17
Loading