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 185 views
1 answer 125 views
1 answer 181 views
1 answer 145 views
1 answer 146 views
1 answer 169 views
...