I have a project with a file structure that looks like this:

I’m trying to move all of the usercontrol code to another file and call the function from the main.cpp. When I try to call the function, I get various errors depending on how I call it:

I’m not sure how to properly call the usercontrol single driver function from the file to the main.cpp. How would I do that?
Pic of usercontrol.h:

Pic of usercontrol.cpp:

C++ isnt my best language, but I think you need an instance of the usercontrol class, or make the usercontrol class static
What you want is to have the functions marked as static
, meaning they belong to the class namespace instead of belonging to an object instance.
In your header, you type
static void singledriver(void);
2 Likes
That would certainly work. But this application isn’t really a good fit for the idea of a class anyway - what does the usercontrol
class really represent? If you never need an instance of it, does it really make sense to make it a class?
I think it would make more sense to just define the functions without sticking them in a class.
1 Like
Its not necessarily bad to have only static members in a class - it puts the methods in a namespace and helps with organization. They are called “pure static classes”, and for example are used in okapilib factories.
However, I agree that in this case, having a class is unnecessary. If you want the organization of a namespace, just use a namespace.
3 Likes