- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用我正在调用的函数构建一个 vector vector<Competition> CompPop()
.我想返回类型为 vector<Competition>
的 vector 信息.下面是我的函数代码,用于返回我的 Competition
的 vector 和 header 。类。
我收到以下错误(我使用的是 Visual Studio,错误消息非常基本,让我猜测我到底做错了什么):
-error C2065: 'Competition' : undeclared identifier
'CompPop' uses undefined class 'std::vector'
'Competition' : undeclared identifier
error C2133: 'info' : unknown size
error C2512: 'std::vector' : no appropriate default constructor available
error C2065: 'Competition' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'temp'
error C3861: 'temp': identifier not found
error C2678: binary '[' : no operator found which takes a left-hand operand of type 'std::vector' (or there is no acceptable conversion)
#pragma once
#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <vector>
#include "LogIn.h"
#include "Registration.h"
#include "Tree.h"
#include "PriorityQueue.h"
#include "Events.h"
#include "Competition.h"
using namespace std;
vector<Competition> CompPop()
{
ifstream myfile("Results.txt");
string line, tcomp, tleader, tfollower, tevents, tplacement;
vector<Competition> info;
istringstream instream;
if(myfile.is_open())
{
int i = 0; // finds first line
int n = 0; // current vector index
int space;
while(!myfile.eof())
{
getline(myfile,line);
if(line[i] == '*')
{
space = line.find_first_of(" ");
tleader = line.substr(0+1, space);
tfollower = line.substr(space + 1, line.size());
}
else
{
if(line[i] == '-')
{
tcomp = line.substr(1, line.size());
Competition temp(tcomp, tleader, tfollower);
info[n] = temp;
}
else
{
if(!line.empty())
{
line = line;
space = line.find_first_of(",");
tevents = line.substr(0, space);
tplacement = line.substr(space + 2, line.size());
info[n].pushEvents(tevents,tplacement);
}
if(line.empty())
{
n++;
}
}
}
}
}
else
{
cout << "Unable to open file";
}
myfile.close();
return info;
}
我的比赛标题:
#pragma once
#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <vector>
#include "LogIn.h"
#include "Registration.h"
#include "Tree.h"
#include "PriorityQueue.h"
#include "Events.h"
#include "CompPop.h"
using namespace std;
struct Competition
{
public:
Competition(string compName, string lead, string follow)
{
Name = compName;
Leader = lead;
Follower = follow;
}
void pushEvents(string name, string place)
{
Events one(name, place);
Eventrandom.push_back(one);
}
string GetName()
{
return Name;
}
string GetLeader()
{
return Leader;
}
string GetFollow()
{
return Follower;
}
string GetEvent()
{
return Event;
}
string GetScore()
{
return Score;
}
~Competition();
private:
string Name, Leader, Follower, Event, Score;
vector<Events> Eventrandom;
};
最佳答案
看起来您没有在源文件中#include
Competition
header 。
顺便说一句,您似乎也在 header 中使用 using namespace std;
。 This is not a good practice .
根据更新的信息进行编辑:
这是一个循环依赖问题。
如果你简单地在CompPop.h中转发声明Competition
和声明CompPop
,并将CompPop
的实现添加到CompPop.cpp中,你会打破这个循环。
因此将 CompPop.h 更改为:
#pragma once
#include <vector>
struct Competition;
std::vector<Competition> CompPop();
关于c++ - 我想返回 vector<Competition> 的函数,但被告知未声明 Competition 并且我正在使用未定义的类 'std::vector',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10359291/
我正在尝试使用我正在调用的函数构建一个 vector vector CompPop() .我想返回类型为 vector 的 vector 信息.下面是我的函数代码,用于返回我的 Competition
在“AmDocs”最近组织的比赛中,我遇到了以下问题:(问题的基本思路) 给定一个大小固定为 12x12 的矩阵。给定六个长度为 6、5、5、4、3、2 的线段。矩阵有空的空间和填充的空间。您必须返回
当一个线程等待一个条件变量时,关联的互斥锁被(原子地)释放(解锁)。当该条件变量(由不同的线程)发出信号时,一个(对于信号)或所有(对于广播)等待线程被唤醒,自动重新获取(锁定)互斥量。 如果一个或多
我将参加 OBI(巴西信息学奥林匹克竞赛,英语),并且我正在尝试过去几年的一些练习。但是我找不到这个练习的解决方案(我翻译了它,所以可能有一些错误): Chocolate Competition Ca
我试图理解 Steven Halim 和 Felix Halim 的书 Competitive Programming 中的“凸包”算法。 “凸包”问题是,给定平面中 n 个点的集合 P,找到一个子集
我试图在远程 Kaggle 内核中使用 Python 模块,但是当我运行 from kaggle.competitions import nflrush 时,出现了这个错误: Could not fi
我正在尝试将 Z3 与 c++ api(版本 Z3 4.1.0.0)一起使用,即我正在尝试解析来自 smt-competition unsat 核心轨道的实例。我(根据示例)编写了以下代码: cont
最近我参加了一个编码挑战,但我只得到了 50% 的分数。很少有测试用例在执行我的代码时失败,我无法找到代码失败的原因。所以我在下面添加了问题和我的代码。感谢您帮助找到测试用例失败的原因。 要求 Com
我是 kaggler 的新兵。 我 fork 一个开放的内核并提交,当我提交我的输出时,按钮 Submit to Competition不工作,以及“您的内核无法使用互联网访问来参加本次比赛”的信息。
我正在研究一些数据结构,我注意到这是一个时间复杂度: O(log(log(n))))-竞争性。 我读到持续竞争是预期时间/最佳时间的比率。但是,拥有一套竞争力意味着什么? 最佳答案 在线算法是一种事先
我正在尝试从 Kaggle 竞赛中下载数据 state-farm-distracted-driver-detection 数据集具有以下目录结构 |-driver_imgs_list.csv |-sa
我正在尝试从 kaggle 比赛中下载数据,但我遇到了标题问题。我已经搜索过,我知道问题是我正在尝试为 kaggle 内核而不是本地内核运行它,但我不知道如何解决这个问题。我知道这是一个愚蠢的问题,但
我刚刚开始使用 OpenCL 1.2 和 C++ 绑定(bind)。我想将写入缓冲区异步排队并在操作完成后获取回调。这是相关代码行的精简版本: cl::Event enqueuingBufferRea
我是一名优秀的程序员,十分优秀!