error: calls a non-static member function with no object arguments.
this error occurs because the class is not instantiated with .
Take a chestnut, for example:
class Student
{
public:
int getAge();
};
The reason for this error may be that when you call the function getAge(), you are doing this:
Student::getAge();
Or do it this way:
Student.getAge();
This means that the member function is called without instantiating the class Student.
Fix one: Instantiate an object first
Student XiaoWang;
int age = XiaoWang.getAge();
Correction 2: Declare member functions as static functions
class Student
{
public:
static int getAge();
};
Student::getAge();
Take chestnuts, for example:
QDir::mkpath(Path);
Error: Calling a non-static member function with no object arguments.
the reasons for this error is that the class does not instantiate and call mkpath function need to first class instantiation,
to:
QDir tempDir;
tempDir.mkpath(Path);
That’s right.
If you write your own class, you can also add the static keyword before the function’s declaration in the class body to declare the function as a static member and call it without instantiation.
such as:
QMessageBox::warning(this,tr("Warning"),tr("No Exist"));
Static member functions can be called directly with “ class :: function name
“.
Read More:
- PHP Fatal error: Call to a member function query() on a non-object in
- Fatal error: Call to a member function bind_param() on a non-object in
- 【ERROR_2】Call to a member function bind_param() on a non-object
- error: invalid use of non-static member function
- Call to a member function fetch_assoc() on a non-object
- call to member function bind_param() on boolean………..
- C ා programming encountered an object reference is required for the non-static field, method, or property error
- Failed to import static file of vue3 static resource. There is no static folder
- A call to an OS function failed
- [C + +] C + + overload operator = must be a nonstatic member function?
- error Expected an assignment or function call and instead saw an expression
- Python TypeError: ‘newline’ is an invalid keyword argument for this function
- non-static variable this cannot be referenced from a static context
- [How to Solve]Warning: connect.static is not a function
- TypeError: descriptor ‘__init__‘ of ‘super‘ object needs an argument
- An undetermined call to function ‘shell’: missing ‘. Stop. Problem encountered when using shell command in makefile
- NDK Version Clang++: error: unknown argument: ‘-static-openmp‘
- C# Member XXX cannot be accessed with an instance with an instance reference;qualify it with a type
- [problem record] objc_ Too many arguments to function call
- SSM project controller layer calls static method to report an error