在C++ Primer,第5版中阅读一个练习的答案,我找到了这段代码:
#ifndef CP5_ex7_04_h
#define CP5_ex7_04_h
#include <string>
class Person {
std::string name;
std::string address;
public:
auto get_name() const -> std::string const& { return name; }
auto get_addr() const -> std::string const& { return address; }
};
#endif
Run Code Online (Sandbox Code Playgroud)
是什么
const -> std::string const&
Run Code Online (Sandbox Code Playgroud)
这个意思是什么意思?
文章声称
template <class T> class tmp {
public:
int i;
};
auto foo()->auto(*)()->tmp<int>(*)(){
return 0;
}
Run Code Online (Sandbox Code Playgroud)
相当于
template <class T> class tmp{
public:
int i;
};
tmp<int> (*(*foo())())() {
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不理解第二个代码示例中的复杂函数.我应该在一开始看哪里?我想是的foo
.但旁边的统计数据foo
将定义foo
为指针......基于第一个代码示例,我将把这个片段转换为
tmp<int> (*)() (*)() foo(){ return 0;}
Run Code Online (Sandbox Code Playgroud)
所以foo是一个函数,返回0,但返回类型很棘手:它的返回类型是函数指针,其返回类型又是返回类型为的函数指针tmp<int>
.
import numpy as np
import matplotlib.pyplot as plt
def f(t):
return np.exp(-t) * np.cos(2*np.pi*t)
t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)
plt.figure(1)
plt.subplot(211)
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')
plt.subplot(212)
plt.plot(t2, np.cos(2*np.pi*t2), 'r--')
plt.show()
Run Code Online (Sandbox Code Playgroud)
据官方Matplotlib文件(https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.figure)一个图形功能
"如果提供了num,并且已存在具有此id的数字,请将其设为活动状态,并返回对它的引用."
我尝试在没有plt.figure的情况下在我的Ipython上执行上述操作,但它仍然显示了两张所需的图片.
class base
{
public:
std::string name() { return basename; }
virtual void print(std::ostream &os) { os << basename; }
private:
std::string basename = "base\n";
};
class derived : public base
{
public:
void print(std::ostream &os) override { base::print(os); os << " derived\n " << i; }
private:
int i;
};
int main()
{
// ex15.14
base bobj;
base *bp1 = &bobj;
base &br1 = bobj;
derived dobj;
base *bp2 = &dobj;
base &br2 = dobj;
// a. this is an …
Run Code Online (Sandbox Code Playgroud)