I know that you can implement a class in multiple files (yes, I know this is a bad idea), but I want to know if it is possible to write a class definition in separate files without getting an override error (maybe some tricks, or else ... )
No, not the same class, but why do you need it?
You can define two classes with the same name in the same namespace (the same signature! It will actually be the same class in general, just defined in two ways) in two different header files and compile your program if your source files do not include both headers. Your application may even be connected, but then at runtime everything will not work as you expect (it will be undefined behavior!) If the classes are not identical.
See Charles Bailey's answer for a more formal explanation.
EDIT:
If you want one class to be defined by more than one file in order to (for example) add automatically generated functions to your class, you could #includeadd a secondary file in the middle of your class.
#include
/* automatically generated file - autofile.gen.h */ void f1( ) { /* ... */ } void f2( ) { /* ... */ } void f3( ) { /* ... */ } /* ... */ /* your header file with your class to be expanded */ class C { /* ... */ #include "autofile.gen.h" /* ... */ };
, partial #, , :
partial
class MyClass { #include "my_class_aspect1.h" #include "my_class_aspect2.h" #include "my_class_aspect3.h" }; #include "my_class_aspect1.inl" #include "my_class_aspect2.inl" #include "my_class_aspect3.inl"
...
1
ClassDef1.h:
class ClassDef { protected: // blah, etc. public: // more blah
-
ClassDef2.h:
public: // Yet more blah. };
.
.. AFAIK, .
. .h, body .cpp .h, , , .h .
, . , .
, ( ).
. 3.2 [basic.def.odr]/5 ISO 14882: 2003.
, , , :
, , ThinkingStiff, ++. , - " " #.
, " " .NET , . ++,.NET , " ". , , , , .
, , , , .
, , , , ( ), . , , , (API) factory . .
, ( ), . , , , .. , .
I , , , , , .
#, , , ++.
, - , , ? , . , gotchas, MI, , , .
- , . - , ( , ).
- , . .
// header file with function declarations class C { public: void f(int foo, int bar); int g(); }; // this goes into a seperate file void C::f(int foo, int bar) { // code ... } // this in yet another void C::g() { // code ... }
There must be a reason why you want to separate the two headers, so I assume that you really want the 2 classes to be combined together to form the components of one (third) class.
Source: https://habr.com/ru/post/1785161/More articles:Why does Javamail throw an IOException if you need to open a plain / text message? - javaКак читать значения сеанса с помощью jQuery - jqueryHow to split semicircular area into color segments using HTML Canvas - html5Performance impact of javax.servlet.Filter? - javaJAXB2 Mtom application violated specification - javaSpring MVC controller adds request object to response - jsonpush pull with multiple remote locations in mercury - version-controlreplaceWith автоматически закрывает тег - jqueryКак получить контент без вложенных элементов с помощью Nokogiri - rubydownward loop with bash variable - bashAll Articles