我试图用函数将2添加到类变量,但它给了我这个undefined reference to addTwo(int)
,即使我已经声明了它。通过主函数调用函数使用类
#include <stdio.h>
#include <iostream>
using namespace std;
class Test {
public:
int addTwo(int test);
int test = 1;
};
int addTwo(int test);
int main() {
Test test;
cout << test.test << "\n";
addTwo(test.test);
cout << test.test;
}
int Test::addTwo(int test) {
test = test + 2;
return test;
}
声明的东西没有定义它。 – MikeCAT