我是C++的新手并且得到了初学者的错误:
myclass.cpp:在函数'int main()'中:
myclass.cpp:14:16:错误:'func'未在此范围内声明
这是代码:
#include <iostream>
using namespace std;
class MyClass{
public:
int func(int);
};
int MyClass::func(int a){
return a*2;
}
int main(){
cout << func(3);
}
Run Code Online (Sandbox Code Playgroud)
我希望你能帮助我.
我有一个小作业问题.
给出以下代码:
int * p;
p = new int;
*p = 5;
Run Code Online (Sandbox Code Playgroud)
问题是:为什么这样做无用
p = 0;
delete p;
Run Code Online (Sandbox Code Playgroud)
但是很有用
delete p;
p = 0;
Run Code Online (Sandbox Code Playgroud)
?
在我看来,两者都没用.如果删除对象,则不能分配新值.
我也得到了两种情况Segmentation fault
.
我想使用智能指针而不是原始指针.如何相应地转换此功能?
Node * List::next(const Node * n) const {
return n->next;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试从函数返回一个数组并使用它的结果.
当我想得到它的长度时,我总是得到一个0:
function myFunc() {
var arr = [];
arr.push("test");
arr.push("another test");
return arr;
}
alert(myFunc.length) // expected 2, but got 0
Run Code Online (Sandbox Code Playgroud)
我希望返回特定范围之间的所有日子.
我的想法是将开始和结束日期转换为unix时间戳并循环遍历它们添加86400(一天中的几秒):
<?php
$start = strtotime('2013-01-01');
$end = strtotime('2013-02-01');
for($i=$start; $i<=$end; $i+86400)
{
echo date("l, d.m.y", $i) . "\n";
}
?>
Run Code Online (Sandbox Code Playgroud)
不幸的是,我只得到同一天:
Tuesday, 01.01.13
Tuesday, 01.01.13
Tuesday, 01.01.13
...
Run Code Online (Sandbox Code Playgroud) 假设我有以下字符串"ab c".
使用正则表达式我想找到子串"b"(请注意字母b之前的空格).
当我这样做时[ b]
,它只找到b之前的空格,而不是字母本身.当我这样做时[ b]+
,它会找到b,但也会找到b之前和之后的空格.即使对于胡说八道也是如此[ bbbbb ]+
.
找到"b"的正确表达是什么?
PS:我在这里测试了我的正则表达式:https://regex101.com/
我正在尝试检查数组中是否已存在元素.我知道至少有两种不同的方法:[1] 和[2].
我测试了它们,但no
在两种情况下都可以:
var myArray = ["Banana", "Orange", "Apple", "Mango"];
if ("Banana" in myArray) {
console.log("yes")
} else {
console.log("no") // <--
}
if (typeof myArray["Banana"] === 'undefined') {
console.log("no") // <--
} else {
console.log("yes")
}
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,我得到no
.我错过了什么吗?
还有,哪一个更快?
我将一些Json反序列化并将其放入具有以下结构的模型中:
模型:
import java.time.LocalDate;
public class MyClass implements Serializable {
String name;
LocalDate date;
// more attributes
public MyClass(...) {
// ...
}
// getters & setters
}
Run Code Online (Sandbox Code Playgroud)
然后我将该类放入ArrayList : List<MyClass> list = new ArrayList<>()
. 该列表如下:
[
{
"name": "peter",
"date": {
"year": "1984",
"month": "10",
"day": "17"
}
},
{
"name": "steve",
"date": {
"year": "1976",
"month": "05",
"day": "04"
}
}
]
Run Code Online (Sandbox Code Playgroud)
我知道想list
按日期排序,所以Steve
之前就是这样Peter
.
我的方法是:
Comparator<Map<String, String>> mapComparator = (Map<String, String> m1, …
Run Code Online (Sandbox Code Playgroud) c++ ×3
javascript ×3
pointers ×2
arrays ×1
collections ×1
date ×1
datetime ×1
dictionary ×1
java ×1
list ×1
loops ×1
php ×1
regex ×1
sorting ×1