Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 什么是整数?_Java - Fatal编程技术网

Java 什么是整数?

Java 什么是整数?,java,Java,整数规划问题是一个数学优化或可行性程序,其中一些或所有变量被限制为整数。您的myintstrict变量被声明为BDictionaryBDictionary的键是int和E是std::string 当您调用myintstrict.removeAny(strData)时,BDictionary::removeAny()方法将E&akastd::string&作为输入,strData是std::string,因此一切正常 在BDictionary内部,其字典成员声明为ABag*ABag的E是KVpai

整数规划问题是一个数学优化或可行性程序,其中一些或所有变量被限制为整数。

您的
myintstrict
变量被声明为
BDictionary
BDictionary
键是
int
E
std::string

当您调用
myintstrict.removeAny(strData)
时,
BDictionary::removeAny()
方法将
E&
aka
std::string&
作为输入,
strData
std::string
,因此一切正常

BDictionary
内部,其
字典
成员声明为
ABag*
ABag
E
KVpair

ABag::removeTop()

因此,当您调用
dictionary->removeTop(returnValue)
时,您传递的是一个
std::string
,其中需要
KVpair
,这就是编译器失败的原因

要执行您正在尝试的操作,您需要修复
BDictionary::removeAny()
方法的实现,以接受
KVpair
,并且您可以为此提取
std::string
,例如:

//BDictionary.h
template <typename Key, typename E>
class BDictionary : public Dictionary<Key, E> {

    ABag<KVpair<Key, E>>* dictionary;   //Dictionary object

    bool removeAny(E& returnValue) {     //The Dictionary method that accepts an E& value       
        KVpair<Key, E> pair;
        bool res = dictionary->removeTop(pair);
        if (res) returnValue = pair.second; // or however KVpair refers to its 2nd element
        return res;
    }
};
//BDictionary.h
模板
B类词典:公共词典{
ABag*字典;//字典对象
boolRemoveAny(E&returnValue){//接受E&value的字典方法
KVpair对;
bool res=字典->移除(成对);
if(res)returnValue=pair.second;//或者KVpair引用其第二个元素
返回res;
}
};
BDictionary::removeAny
中,对
ABag::removeTop
的调用想要“返回”一个
KVPair
。但是
removeAny
仅用于“返回”
E
。您不能将
removeAny
E&returnValue
参数传递到
removeTop
,因为
removeTop
将要返回整对,而不仅仅是值,而且只有值将“适合”在
E&

在不深入和修改
ABag
的内部结构的情况下,我认为最好的方法是在
removeAny
中创建一个临时
KVPair
“destination”,以保存来自
removeTop
的值,然后只传递该对的值部分。这很难看,但它能起作用:

bool removeAny(E &returnValue) {
    KVPair<Key, E> dest;
    bool removed = dictionary->removeTop(dest);
    if(removed) returnValue = std::move(dest.value); // or however you get the value out
    return removed;
}

这需要修改您的呼叫代码(在
bagtestmain.cpp
中)。

您粘贴的错误消息似乎被截断了。你能粘贴完整的编译器输出吗?我用完整的编译器错误更新了帖子。请添加足够的代码,这样我们就可以知道每个上下文中
E
是什么。(比如一个
模板类{
..
};
?)ABag中的E类型是
KVpair
,Dictionary中的E类型是
int
。编译器会通知您,无法将
int
转换为
KVpair
A是有帮助的,因为您这里的内容太零碎和复杂,如果我输入缺少的部分以使其进行编译,我很有可能不会输入您遇到的错误。
bool removeAny(KVPair<Key, E> &dest) {
    return dictionary->removeTop(dest);
}