我的构造函数有点问题.在我的头文件中,我声明:
char short_name_[2];
Run Code Online (Sandbox Code Playgroud)
在我的构造函数中:
Territory(std::string name, char short_name[2], Player* owner, char units);
void setShortName(char* short_name);
inline const char (&getShortName() const)[2] { return short_name_; }
Run Code Online (Sandbox Code Playgroud)
在我的cpp文件中:
Territory::Territory(std::string name, char short_name[2], Player* owner,
char units) : name_(name), short_name_(short_name),
owner_(owner), units_(units)
{ }
Run Code Online (Sandbox Code Playgroud)
我的错误:
Territory.cpp:在构造函数'Territory :: Territory(std :: string,char*,Player*,char)'中:Territory.cpp:15:33:错误:将'char*'赋值给'char [的不兼容类型2]"
我已经想通了,char[2] <=> char*但我不知道如何处理关于我的构造函数和get/setter的问题.
我想检查一个表单,如果输入值为空,但我不知道最好的方法,所以我试过这个:
使用Javascript:
function checkform()
{
if (document.getElementById("promotioncode").value == "")
{
// something is wrong
alert('There is a problem with the first field');
return false;
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<form id="orderForm" onSubmit="return checkform()">
<input name="promotioncode" id="promotioncode" type="text" />
<input name="price" id="price" type="text" value="€ 15,00" readonly="readonly"/>
<input class="submit" type="submit" value="Submit"/>
</form>
Run Code Online (Sandbox Code Playgroud)
有人有想法或更好的解决方案吗?
我是Prolog的新手,所以我在某项任务中遇到了一些问题.任务是编写尾递归谓词count_elems(List,N,Count)条件List_Element > N, Count1 is Count+1.
我的方法:
count_elems( L, N, Count ) :-
count_elems(L,N,0).
count_elems( [H|T], N, Count ) :-
H > N ,
Count1 is Count+1 ,
count_elems(T,N,Count1).
count_elems( [H|T], N, Count ) :-
count_elems(T,N,Count).
Run Code Online (Sandbox Code Playgroud)
错误信息:
ERROR: toplevel: Undefined procedure: count_elems/3 (DWIM could not correct goal)
Run Code Online (Sandbox Code Playgroud)
我不太清楚问题出在哪里.thx任何帮助:)
我在java中搜索保存数据的最佳方法.我有两个带ID和名称的ArrayLists.现在我希望它以最简单,最智能的方式保存.喜欢:
[index] [String ID] [String Name]
[1]["newID"]["Peter]
Run Code Online (Sandbox Code Playgroud)
它背后的想法是,例如,我有名称"彼得",所以我知道索引,所以我得到了ID.传入数据"彼得"得到索引1和ID"newID"
那么最好的方法是实现它.三维数组列表,矢量我不确定,谢谢:)
我有一个小问题.我必须使用相同大小的字符串列表和要比较的字符串.意思是我想比较字符串和第一个列表以获取列表中比较字符串的索引,然后从该索引上的另一个列表中获取另一个字符串.
private String getStringOnIndex(List<String> list1, List<String> list2,String elem)
{
String elem2;
for (int i = 0; i<list1.size();i++) {
if(list1.get(i).equals(elem)){
elem2 = list2.get(i);
return elem2;
} else {
return "nope";
}
}
}
Run Code Online (Sandbox Code Playgroud)
比较两个这样的字符串是不对的.或者我应该使用运算符==.我知道字符串列表的样式并不好,但它只是一个临时解决方案.thx任何帮助:)