我在使用这些静态成员初始化c ++类时遇到了麻烦.有关详细信息,请参阅我的代码
header.h
#ifndef HEADER_H
#define HEADER_H
#include <string>
using namespace std;
class Staff{ public: static string str;};
class Boss{ public: static string str;};
#endif
Run Code Online (Sandbox Code Playgroud)
staff.cpp
#include "header.h"
string Staff::str = "(staff)";
Run Code Online (Sandbox Code Playgroud)
boss.cpp
#include "header.h"
string Boss::str = "I call " + Staff::str;
Run Code Online (Sandbox Code Playgroud)
main.cpp中
#include <iostream>
#include "header.h"
int main(){cout << Boss::str << endl;}
Run Code Online (Sandbox Code Playgroud)
预编译:
g++ -c boss.cpp
g++ -c staff.cpp
ar rcs lib.a boss.o staff.o
ar rcs rlib.a staff.o boss.o
Run Code Online (Sandbox Code Playgroud)
编译,运行和结果:
g++ main.cpp staff.cpp boss.cpp ; ./a.out …Run Code Online (Sandbox Code Playgroud) c++ static-variables static-libraries segmentation-fault static-initialization
让我看看我的代码
代码1:
(eqv? 'lambda 'quote)
Run Code Online (Sandbox Code Playgroud)
返回 #f
代码2:
(case 'lambda ('quote "equal") (else "not equal"))
Run Code Online (Sandbox Code Playgroud)
返回"not equal"但生成警告;;; <stdin>:17:0: warning: duplicate datum quote in clause ((quote quote) "equal") of case expression (case (quote lambda) ((quote quote) "equal") (else "not equal"))
Code3:奇怪的结果
(case 'quote ('lambda "equal"))
Run Code Online (Sandbox Code Playgroud)
返回"equal",没有警告
我使用了解释代码guile (GNU Guile) 2.0.11.以下是gnucase语法的描述
使用eqv将评估结果与所有基准进行比较?
我怎样才能在Python的2列向量的内积 numpy
下面的代码不起作用
import numpy as np
x = np.array([[1], [2]])
np.inner(x, x)
Run Code Online (Sandbox Code Playgroud)
它回来了
array([[1, 2],
[2, 4]])`
Run Code Online (Sandbox Code Playgroud)
代替 5
对于某些值,调用 hasOwnProperty 会引发错误。
我们来检查一下下面的代码:
null.hasOwnProperty('bar') // Error
undefined.hasOwnProperty('bar') // Error
(0).hasOwnProperty('bar') // Returns false
Run Code Online (Sandbox Code Playgroud)
除了nulland之外,还有其他变量undefined在调用 with 时会引发错误吗.hasOwnProperty?
设置对象属性的相同问题:
null.bar // Error
undefined.bar // Error
(0).bar === undefined // Returns true
Run Code Online (Sandbox Code Playgroud)
=========
在我的 Node.js 环境中抛出错误的另一种情况:
在浏览器中
'use strict';
(0).bar = 0; // Nothing happens
Run Code Online (Sandbox Code Playgroud)
在 Node.js v.10.3.0 中:
(0).bar = 0; // Nothing
'use' strict';
(0).bar === undefined; // Returns true
true.bar === undefined; // Returns true
''.bar = '';// STILL NOTHING HAPPENS
(0).bar = …Run Code Online (Sandbox Code Playgroud) 我想声明一个 Typescript 数组类型,其中最后一个元素是可选的。有没有什么优雅的方法来实现这一目标?
const test = (a: [string, string, any | undefined]) => console.log(a)
test(['foo', 'bar'])
Run Code Online (Sandbox Code Playgroud)
在test(...)函数调用中,ts 详细说明此错误
Argument of type '[string, string]' is not assignable to parameter of type '[string, string, any]'.
Property '2' is missing in type '[string, string]' but required in type '[string, string, any]'.(2345)
Run Code Online (Sandbox Code Playgroud) arrays ×1
c++ ×1
ecmascript-6 ×1
guile ×1
javascript ×1
node.js ×1
numpy ×1
python ×1
quote ×1
scheme ×1
strict ×1
tuples ×1
typescript ×1
vector ×1