我有一个结构作为值类型的地图
map<int id, struct_t*> table
struct_t
{
int prev;
int wt;
string name;
}
Run Code Online (Sandbox Code Playgroud)
仅使用prev,我需要找到相应的id.非常感谢提前!
编辑:
int key=0;
for(auto it = table.begin(); it != table.end(); ++it)
{
if(table[(*it).first].prev == ?)
}
Run Code Online (Sandbox Code Playgroud)
这就是我的地图数据的样子:
id prev abundance thing
1573 -1 0 book
1864 1573 39 beds
2075 1864 41 tray
1760 2075 46 cups
Run Code Online (Sandbox Code Playgroud)
对于每个id,我需要找到NEXT匹配id.因此,对于来自prev列的1573,我需要找到匹配的'id',即1864.此外,std :: next不起作用,因为数据集可以具有匹配的id,不一定在下一个元素中.希望这有帮助!
请帮帮我!!! 我的老板已经很失望我花了这么多时间学习C++(已经有3周了!)
我在 xcode 和 vi 上遇到了这个错误。Python 表示行类 LeastModel 有一个 IndentationError: Expected an indented block。我在 Xcode 上检查了我的首选项,以使用 4 个空格作为制表符,并且在我一直使用制表符的任何地方。请帮我!
def make_model(data,model):
class LeastModel():
"""
linear system solved using linear least squares
This class serves as an example that fulfills the model interface needed by the ransa function.
"""
def __init__(self,input_columns,output_columns):
self.input_columns = input_columns
self.output_columns = output_columns
#self.debug = debug
Run Code Online (Sandbox Code Playgroud) 这是我的结构,我正在尝试为此编写默认构造函数.
struct Cnode
{
typedef std::map<char, int> nextmap;
typedef std::map<char, int> prevmap;
Cnode() : nextmap(), prevmap() {} //error
Cnode(const nextmap2, const prevmap2) : nextmap(nextmap2), prevmap(prevmap2) {}
};
Run Code Online (Sandbox Code Playgroud)
请帮我理解这个错误意味着什么:
Type 'nextmap'(aka 'map<char,int>') is not a direct or virtualbase of 'Cnode'
Type 'prevmap'(aka 'map<char,int>') is not a direct or virtualbase of 'Cnode'
Run Code Online (Sandbox Code Playgroud)