How to hide constructor in class with C++

2 Answers

0 votes
#include <iostream>

class Example {
private:
    Example();
};

int main() {
    Example ex; // error: ‘Example::Example()’ is private within this context
}




/*
run:

error: ‘Example::Example()’ is private within this context

*/

 



answered Jan 29, 2023 by avibootz
0 votes
#include <iostream>

class Example {
public:
    Example() = delete;
};

int main() {
    Example ex; // error: ‘Example::Example()’ is private within this context
    
}




/*
run:

error: ‘Example::Example()’ is private within this context

*/

 



answered Jan 29, 2023 by avibootz

Related questions

2 answers 278 views
1 answer 206 views
1 answer 266 views
1 answer 232 views
1 answer 262 views
1 answer 265 views
...