次のようなクラスの課題があります。
2 つの int パラメーターを取り、int を返す関数の宣言を記述し、要素がこの関数ポインター型を持つベクトルを宣言します。
関数とベクトルは両方とも int なので、これは正しいですか? 私はまだポインターについて本当に曖昧です。これは私が持っているものです:
#include <iostream>
#include <vector>
using std::cin; using std::cout; using std::endl; using std::vector;
// This is my function that take two ints and returns and int
int AddFunc ( int a, int b) { int addResult; addResult = a + b; return (addResult);}
int main()
{
vector <int> v1; // Declare a vector whose elements have this functions pointer types
int add1, add2, add3 = 0;
cout << "Enter two numbers to be added with my AddFunc function: ";
cin >> add1 >> add2;
add3 = AddFunc (add1, add2);
cout << "The numbers added equal: " << add3 << endl;
v1.push_back(add3);
cout << "The first element in the vector v1 is: " << v1 [0] << endl;
return 0;
}