c++ - Force user to declare object const -


this question has answer here:

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

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -