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:
- error: invalid use of non-static member function
- C ා programming encountered an object reference is required for the non-static field, method, or property error
- PHP Fatal error: Call to a member function query() on a non-object in
- libxx.so: undefined reference, vector.reserve(n) [How to Solve]
- What is cs0120 error
- non-static variable this cannot be referenced from a static context
- OTS parsing error: invalid version tag
- Macro generated_ UCLASS_ Body () and generated_ Analysis of body ()
- Copy forbidden in C + +++
- Solution of idea using @ Autowired annotation to report errors
- [How to Solve]Warning: connect.static is not a function
- About the prompt: invalid use of incomplete type
- C# Member XXX cannot be accessed with an instance with an instance reference;qualify it with a type
- Uncaught syntax error: unexpected token ‘< 0‘
- Failed to import static file of vue3 static resource. There is no static folder
- [C + +] C + + overload operator = must be a nonstatic member function?
- error: expected unqualified-id before ‘.’ token
- Fatal error: Call to a member function bind_param() on a non-object in
- Initialization order of Java objects
- Array initializer is not allowed here