我对“函数”的getmaxyx工作方式感到困惑……因为我知道它实际上是一个宏。但是这个宏是如何工作的呢?
代码示例:
#include <ncurses.h>
int main() {
int col, row;
initscr();
getmaxyx(stdscr,row,col);
endwin();
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我想do_something根据泛型类型是否实现来实现有条件的T实现Debug。有没有办法做这样的事情?
struct A(i32);
#[derive(Debug)]
struct B(i32);
struct Foo<T> {
data: T,
/* more fields */
}
impl<T> Foo<T> {
fn do_something(&self) {
/* ... */
println!("Success!");
}
fn do_something(&self)
where
T: Debug,
{
/* ... */
println!("Success on {:?}", self.data);
}
}
fn main() {
let foo = Foo {
data: A(3), /* ... */
};
foo.do_something(); // should call first implementation, because A
// doesn't implement Debug
let foo = Foo {
data: …Run Code Online (Sandbox Code Playgroud) 我有一个关于复制构造函数的问题,假设一个class A包含一个int默认构造函数的复制构造函数(?)和一个接收一个构造函数的构造函数.int
class A {
int value;
public:
A(): value(0) {} // Default
A(A& copy): value(copy.value) {} // Copy (?)
A(const int n): value(n) {} // Receives an int for 'value'
int get_value() { return value; } // Return value
};
Run Code Online (Sandbox Code Playgroud)
并且包含一个A pointer名为的类BoxForA:
class BoxForA {
A *obj;
public:
BoxForA(): obj(nullptr) {}
BoxForA(const int a) { obj = new A(a); }
A popf(){ return *obj; } // Returns the content of …Run Code Online (Sandbox Code Playgroud)