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 283 views
1 answer 211 views
1 answer 267 views
1 answer 243 views
1 answer 269 views
1 answer 277 views
...