I have two .cpp files and one header ".h". I decided to output the GenCan1 result to main, but I get this error (Error C3867 "TElection :: GetCan1": nonstandard syntax; use "&" to create a pointer to a member)
main.cpp #include <iostream> #include <EClass.h> #include <stdafx.h> using namespace std; int main() { std::cout << TElection::GetCan1<<std::endl; system("pause"); } EClass.h class TElection { protected: float can1, can2, can3; public: TElection(); TElection(TElection &el); TElection(float a, float b, float c); ~TElection(); float GetCan1(); void SetCan1(float i); }; Election.cpp #include <iostream> #include <EClass.h> #include <stdafx.h> TElection::TElection() { can1 = 0; } TElection::TElection(TElection& el) { can1 = el.can1; } TElection::TElection(float a, float b, float c) { can1 = a; } TElection::~TElection() { can1 = -1; } float TElection::GetCan1() { return(can1); } void TElection::SetCan1(float i) { if ((i >= 10) && (i < 0)) can1 = 10; else can1 = i; std::cout << "can1=" << can1; }
()to denote a function call. And also read about how to give the code in the questions: the minimum reproducible example . - 伪位蔚蠂慰位蠀蟿GetCan1()function is not staticstatic, which means that in order to be able to call it, you need to provide an instance of theTElectionclass, create an object, i.e. For example, like this:TElection obj;continue to call theobjfunction:obj.GetCan1(). All this is said in any textbook on language in its basic part. - 伪位蔚蠂慰位蠀蟿 pm