Where to put own functions for use in several classes
-
Hi,
I need to create a function which I need to use in several windows. In PHP I could create a function anywhere any use it anywhere.
How can I do this in qt5?
Do I need to create a new class and create static functions or do I just create a new header and new cpp file and put the functions there, include the header and use them?
What will be the right way in qt5?
-
Both methods will work. The more accepted C++ way is to use static class methods and include the header where needed.
-
@Kent-Dorfman said in Where to put own functions for use in several classes:
is to use static class methods and include the header where needed.
Then the function must not be static ...
-
@Christian-Ehrlicher said in Where to put own functions for use in several classes:
@Kent-Dorfman said in Where to put own functions for use in several classes:
is to use static class methods and include the header where needed.
Then the function must not be static ...
I think @Kent-Dorfman talked about static member functions, a la:
// Header class Foo { public: static void bar(); } // C++ file void Foo::bar() { // ... }
while you meant
static
functions:// C++ file static void bar() { }
which are indeed not visible outside this C++ file.
Uhm, C++ is hard, actually...
Regards