gpt4 book ai didi

c++ - 从 std::map,std::pair
转载 作者:行者123 更新时间:2023-11-30 00:48:16 25 4
gpt4 key购买 nike

我已经定义了新类型:

typedef int(* func) (const std::vector<cv::Mat>&, cv::Mat&);

然后我做了类(class)成员:

std::map< std::string, std::pair<int,func> > functions;

在函数中,第一行:

pair<funcId,func> functionSet::getRandomFunction() const
{
map<string, pair<int,func>>::iterator it = functions.begin();
std::advance(it, functions.size());

string name = it->first;
func function = it->second.second;
int argumentsNumber = it->second.first;
funcId id = make_pair(argumentsNumber,name);

pair<funcId,func> p = make_pair(id,function);

return p;
}

我遇到了这个错误:

error: conversion from 'std::map, std::pair&, cv::Mat&)> > ::const_iterator {aka std::_Rb_tree_const_iterator, std::pair&, cv::Mat&)> > >}' to non-scalar type 'std::map, std::pair&, cv::Mat&)> >::iterator {aka std::_Rb_tree_iterator, std::pair&, cv::Mat&)> > >}' requested map>::iterator it = functions.begin();

最佳答案

您的方法标记为 const,因此 this 的类型为 const functionSet*。改变你的第一行:

map<string, pair<int,func>>::const_iterator it = functions.begin();

或者如果您的编译器支持 C++11 标准:

auto it = functions.cbegin();

关于c++ - 从 std::map<std::basic_string<char>,std::pair<int,int(*)(const std::vector::Mat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32150117/

25 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com