小编Kev*_*rez的帖子

getmaxyx 如何工作?(来自诅咒)

我对“函数”的getmaxyx工作方式感到困惑……因为我知道它实际上是一个宏。但是这个宏是如何工作的呢?

代码示例:

#include <ncurses.h>

int main() {
  int col, row;
  initscr();
  getmaxyx(stdscr,row,col);
  endwin();
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

c curses ncurses

5
推荐指数
1
解决办法
6060
查看次数

如何根据泛型类型是否实现特征以不同方式实现函数?

我想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)

generic-programming rust

5
推荐指数
1
解决办法
577
查看次数

为什么复制构造函数需要是const?

我有一个关于复制构造函数的问题,假设一个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)

c++ constructor c++11

2
推荐指数
1
解决办法
134
查看次数

标签 统计

c ×1

c++ ×1

c++11 ×1

constructor ×1

curses ×1

generic-programming ×1

ncurses ×1

rust ×1