[英]Error for pointer to member in C++
Header file 头文件
#include <iostream>
#include <cstring>
const unsigned MaxLength = 11;
class Phone {
public:
Phone(const char *phone) {
setPhone(phone);
}
void setPhone(const char Phone[ ]);
const char* getPhone();
private:
char phone[MaxLength+1];
};
Cpp file Cpp文件
#include "Phone.h"
#include <iostream>
#include <ctype.h>
#include <cstring>
using namespace std;
bool checkNum(char num[]);
void Phone::setPhone(const char Phone[ ]) {
strncpy(phone, Phone, MaxLength);
phone[MaxLength] = '\0';
}
const char* Phone::getPhone() {
return phone;
}
int main() {
Phone i1("12345678901");
cout << i1.getPhone() << endl;
if (checkNum(i1.getPhone))
cout << "Correct" << endl;
else
cout << "Invalid Wrong" << endl;
}
bool checkNum(char num[]) {
bool flag = true;
if (isdigit(num[0]) == 0)
flag = false;
return flag;
}
When I tried to compile, I get this error: 当我尝试编译时,出现以下错误:
error C3867: 'Phone::getPhone': function call missing argument list;
错误C3867:'Phone :: getPhone':函数调用缺少参数列表; use '&Phone::getPhone' to create a pointer to member
使用'&Phone :: getPhone'创建一个指向成员的指针
I'm getting an error on this line "if (checkNum(i1.getPhone))". 我在“ if(checkNum(i1.getPhone))”这一行出现错误。 I created a Phone object and what I am trying to do is use the function checkNum to see if the first index of the array is a number.
我创建了一个Phone对象,然后尝试使用checkNum函数查看数组的第一个索引是否为数字。 Am I referencing the object wrong?
我引用的对象有误吗? Should I use indirect selection operator instead?
我应该改用间接选择运算符吗? Any idea what I am doing wrong?
知道我在做什么错吗?
Thanks 谢谢
You are missing a pair of parentheses after getPhone
in if (checkNum(i1.getPhone))
; 在
if (checkNum(i1.getPhone))
中,在getPhone
之后缺少一对括号; it should be if (checkNum(i1.getPhone()))
. 应该是
if (checkNum(i1.getPhone()))
。
The line: 该行:
if (checkNum(i1.getPhone))
should be 应该
if (checkNum(i1.getPhone()))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.