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 162 views
1 answer 109 views
1 answer 167 views
1 answer 128 views
1 answer 127 views
1 answer 160 views
...