dmitriy.ogorodnikov Posted October 2, 2014 Share Posted October 2, 2014 I've written a class with several functions. How can I define functions' bodies in another file ? Class declaration is in *.h-file. I would like to create another file with class functions definitions. For example, in C++ language - class declaration is in *.h-file, class definition is in *.cpp-file. How is it in Unigine script ? Link to comment
azagniy Posted October 2, 2014 Share Posted October 2, 2014 Hi. In Unigine script you can write function implementation in a declaration "*.h" file like this: class Foo { void foo() { log.message(__FUNC__ + ": called\n"); } }; And you can write implementation separately from declaration like this: class Foo { void foo(); }; Foo::foo() { log.message(__FUNC__ + ": called\n"); } But there is no difference between *.cpp and *.h files in Unigine script. These extensions just a formality. See more at https://developer.unigine.com/en/docs/1.0/scripting/language/preprocessor#include Link to comment
dmitriy.ogorodnikov Posted October 2, 2014 Author Share Posted October 2, 2014 Thank you for quick answer. Yes, I can write declaration and definition separatelly in one file. But can I write them in two separate files ? Link to comment
azagniy Posted October 2, 2014 Share Posted October 2, 2014 Hi. You can include implementation by simple #include: // test.h file class Foo { void foo(); }; // test.cpp file #include <test/test.h> void Foo::foo() { log.message(__FUNC__ + ": called\n"); } //main.cpp file #include <test/test.cpp> int init() { Foo f = new Foo(); f.foo(); return 1; } Link to comment
dmitriy.ogorodnikov Posted October 2, 2014 Author Share Posted October 2, 2014 Thank you very much! I did all the same before, but I include test.h in main.cpp (and don't include test.cpp) - because I thought in C/C++ style. After I've included test.cpp in main.cpp - all works correct. Now I understand your words: But there is no difference between *.cpp and *.h files in Unigine script. These extensions just a formality. Link to comment
Recommended Posts