[英]C++ compiling error
I have a compiling error in C++ using classes. 我在使用类的C ++中出现编译错误。 I have worked with classes before and have never encountered this error.
我以前使用过类,从未遇到过此错误。 I have tried adding static before the method
ImprtData
but that only prompted more errors. 我尝试在方法
ImprtData
之前添加static,但这只会提示更多错误。
error: invalid use of non-static member function bank.ImprtData;
here is my .cpp 这是我的.cpp
#include "componets.h"
User::User() {
std::cout << "loaded" << std::endl;
}
void User::ImprtData() {
std::cout << "loaded.\n";
}
and here is my .h 这是我的.h
#include <sstream>
#include <fstream>
#include <vector>
#include <iostream>
#include <string>
class User {
public:
User();
void write();
void launch_main_menu();
void login();
void ImprtData();
private:
void deposit();
void withdrawl();
std::string account_name;
int account_pin;
float account_balance;
std::string account_user_name;
};
and finally my main 最后是我的主
#include "componets.h"
int main() {
std::cout << "Welcome to Bank 111.\n";
User bank;
bank.ImprtData;
return 0;
}
This is essentially a simple typo. 这本质上是一个简单的错字。 Replace
更换
bank.ImprtData;
with 同
bank.ImprtData();
to call the function. 调用该函数。 The expression
bank.ImprtData
is confusing the compiler since it's interpreting it as the address of a function, and issues a diagnostic since the function is not static
. 表达式
bank.ImprtData
其解释为函数的地址,这使编译器感到困惑,并且由于该函数不是static
,因此发出了诊断信息。
bank.ImprtData;
should be bank.ImprtData();
应该是
bank.ImprtData();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.