In my C++ project, one of the .cpp files has a class declared. Now I want to instantiate this class in another .cpp file in the same project, but I get this error message:
error C2248: 'Processor' : cannot access private member declared in class 'Processor'
c:\Test\wrapper.cpp : see declaration of 'Processor'
We can’t redefine the class using a different access specifier, it gets the default private access specifier.
How can I make this work?
You can’t (in a clean way at least), and you shouldn’t.
Making fields
private(even by default) is the programmer’s way of telling you you’re not supposed to instantiate this class.Also, if a class is defined inside a
cppfile, it’s only visible in that translation unit. You don’t includecppfiles. If you must, move the definition inside a header and include that, but not thecpp.