在C 中的初学者,我面临此问题错误C3867

beginner in c++ and i face this problem error C3867

本文关键字:问题 错误 C3867 初学者      更新时间:2023-10-16

这是我的第一个C 项目,我遇到了这个问题错误C3867

我的main代码是

#include <string>
#include <iostream>
#include "Car.h"
int main() {
  Car c1;
  c1.setMaker("Honda");
  c1.setModel(2018);
  cout << "This Car Made By" << c1.getMaker << "n";
  cout << "This Car Model" << c1.getModel << "n";
}

标题是

#pragma once
#include <string>
using namespace std;
class Car {
 private:
  string maker;
  int model;
 public:
  void setMaker(string m);
  string getMaker();
  void setModel(int m);
  int getModel();

CPP是

#include "Car.h"
void Car::setMaker(string l) { maker = l; }
string Car::getMaker() { return maker; }
void Car::setModel(int m) { model = m; }
int Car::getModel() { return model; }

这是错误消息: error C3867: 'Car::getMaker': non-standard syntax; use '&' to create a pointer to member

我已经尝试了我作为初学者所知道的一切,但我无法使它起作用:(

您需要在最后使用参数列表调用函数,即使该列表为空。

例如

c1.getMaker是GetMaker函数的地址

c1.getMaker()实际上调用函数