i want to change the “value” when run my app.
but when i call RS232::PackageRecived in “RS232.cpp” i revived This Error :
Error 1 error C2352: ‘RS232::PackageRecived’ : illegal call of non-static member
//////////////////////////////////////////// RS232.cpp FILE
#include "RS232.h"
void RS232::PackageRecived()
{
value =123;
}
void TryCallPackageRecived()
{
RS232::PackageRecived(); // my compiler error is here
}
int RS232::Connect()
{
TryCallPackageRecived();
}
RS232::RS232(void)
{
}
RS232::~RS232(void)
{
}
//////////////////////////////////////////// RS232.h File
class RS232
{
public:
int value;
int Connect();
void PackageRecived();
RS232(void);
~RS232(void);
};
//////////////////////////////////////////// Main.cpp File
#include "RS232.h"
RS232 RS;
int main()
{
RS.Connect();
}
Your function, “TryCallPackageRecived()” is not a member of the RS232 class. It’s trying to call a member function of RS232 that is not static. This is not allowed. When you want to call a non-static member function you need to call it on a particular object.
In this case, you could do:
If you want to allow for multiple objects, you could modify your TryCallPackageRecived function to take a pointer to the RS232 object: