c++ - Force user to declare object const -
this question has answer here:
- c++ class mandates const objects 4 answers
is there way force user of class construct const objects based on data used constructor?
for example, consider small wrapper class around buffer can const or non-const
class wrapper { public: wrapper(const char*); wrapper(char*); }; now if user supplying const, can force them declare object const on compile time. is
// have if input const const char* a; // not compile wrapper w(a); // const wrapper(a); any ideas?
you can't in constructor can create factory returns cost objects refs or pointers. need disable copy , copy construction , may not provide value.
Comments
Post a Comment