我試圖用函數將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