C++ vector size 新手不知道这个编译错误为什么
#include<iostream>#include<vector>usingnamespacestd;classSolution{public:vector<int>t...
#include<iostream>
#include <vector>
using namespace std;
class Solution {
public:
vector<int> twoSum(vector<int> &numbers, int target) {
vector<int> result;
vector<int>::size_type i, j;
int find = 0;
cout << numbers.size; //这里会报错
错误 1 error C3867: “std::vector<int,std::allocator<_Ty>>::size”: 函数调用缺少参数列表;请使用“&std::vector<int,std::allocator<_Ty>>::size”创建指向成员的指针
for (i = 0; i < numbers.size; i++)
{
for (j = i+1; j < numbers.size;j++)
if (numbers[i] + numbers[j] == target)
{
find = 1;
result.push_back[i];
result.push_back[j];
break;
}
if (find)
break;
}
return result;
}
};
int main()
{
vector<int> numbers;
int number;
while (cin >> number)
{
numbers.push_back(number);
}
cout << "Input the target" << endl;
int target;
cin >> target;
Solution s;
vector<int>result;
result = s.twoSum(numbers, target);
for (int i = 0; i < result.size; i++)
{
cout << result[i]<<endl;
}
} 展开
#include <vector>
using namespace std;
class Solution {
public:
vector<int> twoSum(vector<int> &numbers, int target) {
vector<int> result;
vector<int>::size_type i, j;
int find = 0;
cout << numbers.size; //这里会报错
错误 1 error C3867: “std::vector<int,std::allocator<_Ty>>::size”: 函数调用缺少参数列表;请使用“&std::vector<int,std::allocator<_Ty>>::size”创建指向成员的指针
for (i = 0; i < numbers.size; i++)
{
for (j = i+1; j < numbers.size;j++)
if (numbers[i] + numbers[j] == target)
{
find = 1;
result.push_back[i];
result.push_back[j];
break;
}
if (find)
break;
}
return result;
}
};
int main()
{
vector<int> numbers;
int number;
while (cin >> number)
{
numbers.push_back(number);
}
cout << "Input the target" << endl;
int target;
cin >> target;
Solution s;
vector<int>result;
result = s.twoSum(numbers, target);
for (int i = 0; i < result.size; i++)
{
cout << result[i]<<endl;
}
} 展开
2个回答
2017-08-17
展开全部
class Window_mgr
{
public:
typedef vector<Screen>::size_type ScreenIndex;
Window_mgr();
void clear(ScreenIndex);
ScreenIndex addscreen(const Screen &);
~Window_mgr();
private:
vector<Screen> screens{Screen(10,20)};
};
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询