小编unD*_*rbs的帖子

?: 运算符在 C 中究竟是如何工作的?

我有一个问题,编译器如何对以下代码进行操作:

#include<stdio.h>

int main(void)
{
  int b=12, c=11;
  int d = (b == c++) ? (c+1) : (c-1);
  printf("d = %i\n", d);
}
Run Code Online (Sandbox Code Playgroud)

我不知道为什么结果是???d = 11.

c syntax increment conditional-operator post-increment

10
推荐指数
3
解决办法
422
查看次数

Python 和 Matplot:如何按点绘制简单的形状?

我只想按点绘制简单的形状,如下所示:

import matplotlib.pyplot as plt

rectangle = [(0,0),(0,1),(1,1),(1,0)]
hexagon = [(0,0),(0,1),(1,2),(2,1),(2,0),(1,-1)]
l_shape = [(0,0),(0,3),(1,3),(1,1),(3,1),(3,0)]
concave = [(0,0),(0,3),(1,3),(1,1),(2,1),(2,3),(3,3),(3,0)]

for points in [rectangle, hexagon, l_shape, concave]:
    # 1. Can I get rid of the zip? plot directly by points 
    # 2. How can I make the shape complete?
    xs, ys = zip(*points)
    plt.plot(xs, ys, 'o')
    plt.plot(xs, ys, '-')

    automin, automax = plt.xlim()
    plt.xlim(automin-0.5, automax+0.5)
    automin, automax = plt.ylim()
    plt.ylim(automin-0.5, automax+0.5)
    # Can I display the shapes 2 in 1 line?
    plt.show()
Run Code Online (Sandbox Code Playgroud)

我的问题是 …

python matplotlib

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

如果它是模板,为什么禁止 decltype'ing 父类的成员?

如果基类在派生类中模板化,为什么基类的成员在派生类中不可用?

在编译时,所有类型都应该被实例化,所以我不明白它有什么不同或为什么不同。我可以看到一个关于能够创建无法解析的类型的论点;但是,这感觉像是编译时错误,而不是对语言的限制。

更明确地说,为什么这有效?

template<typename T>
class A{
protected:
   int member;
};

class B: public A<int>{
   decltype(member) another_member;
};
Run Code Online (Sandbox Code Playgroud)

但是,这不是吗?

template<typename T>
class A{
protected:
   int member;
};

template<typename T>
class B: public A<T>{
   decltype(member) another_member;
};
Run Code Online (Sandbox Code Playgroud)

c++ templates language-design

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