我遇到了与 Typescript Readonly不一致的情况,我不明白。
Typescript v3.9.2 游乐场:这里
interface Thing {
name: string;
}
interface Obj {
arr: Thing[];
thing: Thing;
}
const myArr : Readonly<Thing[]> = [{name: 'a'}, {name: 'b'}];
const myThing : Readonly<Thing> = {name: 'foo'};
const myObj: Obj = {
thing: myThing,
arr: myArr, // This throws a compile error
}
Run Code Online (Sandbox Code Playgroud)
上面的代码给我以下编译错误:
The type 'readonly Thing[]' is 'readonly' and cannot be assigned to the mutable type 'Thing[]'.(4104)
Run Code Online (Sandbox Code Playgroud)
这个错误是有道理的,我将只读数组分配给可变数组类型。
我不明白的是为什么我没有得到 的thingprop 的类似错误myObj。
我认为将 a …
我正在用css围绕圆形路径旋转div,我想让它在悬停时改变颜色.
请参阅此处的演示:http://jsfiddle.net/gg7tnueu/1/
html,
body {
height: 100%;
margin: 0;
}
.planet {
border-radius: 50%;
border: 2px solid #1a1a1a;
position: absolute;
margin: auto;
/*top: 50%;*/
-webkit-animation: orbit 6s infinite linear;
-webkit-backface-visibility: hidden;
-webkit-transform: translateZ(0);
animation: orbit 6s infinite linear;
backface-visibility: hidden;
transform: translateZ(0);
}
.planet.code {
-webkit-transform-origin: 8.5vh 7.875vh;
transform-origin: 8.5vh 7.875vh;
}
.planet.code:hover {
background: red;
}
@-webkit-keyframes orbit {
0% {
-webkit-transform: rotate(0);
}
100% {
-webkit-transform: rotate(360deg);
}
}
@keyframes orbit {
0% {
transform: …Run Code Online (Sandbox Code Playgroud)我正在尝试实现二进制搜索树类,但编译器会抛出错误.bstNode.h文件在这里:
template <class Item, class Key>
class bstNode
{
public:
bstNode();
bstNode(const Item& init_data, const Key& init_key, bstNode<Item, Key> *init_left, bstNode<Item, Key> *init_right);
~bstNode();
bstNode<Item, Key>* tree_copy(const bstNode<Item, Key>*& root);
private:
Item data;
Key key;
bstNode* left;
bstNode* right;
};
template <class Item, class Key>
//line 83 in the original code is below
bstNode<Item, Key>* bstNode<Item, Key>::tree_copy(const bstNode<Item, Key>*& root)
{
bstNode<Item, Key>* l_ptr;
bstNode<Item, Key>* r_ptr;
if (root == NULL) return NULL;
l_ptr = tree_copy(root -> left());
r_ptr = …Run Code Online (Sandbox Code Playgroud) [编者注:我已经编辑了标题,试图在将来对其他人有用.为了给回答者一个信誉,这只是"为什么这不起作用?" 他们回答的问题!]
top -> ...无论Node*尝试将哪些代码推送到矢量子代,以下代码都会在具有分段错误的行中崩溃.有谁知道这可能导致什么?
struct Node
{
string data;
struct Node* parent;
vector<struct Node*> children;
};
struct Node* push(string word, struct Node* top)
{
Node* temp = (struct Node*) malloc(sizeof(struct Node));
temp -> data = word;
temp -> parent = top;
return temp;
}
int main()
{
Node* top = push("blah", NULL);
Node* temp = NULL;
top -> children.push_back(temp);
}
Run Code Online (Sandbox Code Playgroud)