1. In C++ when your method doesn't have a parameter list you don't have to write
void
in place of the parameter list. In plain C you had to do this because there a function without any parameters is a vararg function if you don't put the
void
there but in C++ its just noise, an empty parameter list in C++ isn't vararg!
2. In C++ its better to keep all member variables private and make public or private set/get methods for them like this:
class Jointdetails
{
public:
Jointdetails();
~Jointdetails();
bool IsChecked() const
{
return Checked;
}
void SetChecked(bool checked)
{
Checked = checked;
}
private:
bool Checked;
};
Another good practice is to give noun member variable names and verb method names like SetXXX(), GetXXX(), DoThis(), DoThat(), the only exception are some bool getter methods that start with "Is" like in my example.
3. If you need the Checked variable in every instances then you are already OK, if you need this Checked variable only onece in your application then you can make it static and you can do it like this:
jointdetails.h:
class Jointdetails
{
public:
static bool IsChecked();
static void SetChecked(bool checked);
};
jointdetails.cpp:
#include "Jointdetails.h"
static bool g_Checked = false;
bool Jointdetails::IsChecked()
{
return g_Checked;
}
void Jointdetails::SetChecked(bool checked)
{
g_Checked = checked;
}
This way you can call
Jointdetails::IsChecked()
anywhere in you application.