小编LRD*_*RDX的帖子

在 C++ 继承中从父调用子方法的最佳方法

我在多态类和继承方面遇到了麻烦。

我有一个父类

//calibration.h 
class Calibration {
private:
public:
void init();
void calc():
void close();
void saveFile();
}

//calibration.cpp
Calibration::Calibration(){}
void Calibration::saveFile(){
std::ofstream out;
    out.open("cores.arff");
out << " " << std::endl;
out.close();
}
Run Code Online (Sandbox Code Playgroud)

我有两个孩子

//automatic.cpp 
Automatic::Automatic(){}
void Automatic::config(){
....
}
void Automatic::calibrate(){
....
}

void Calibrate::init(){
 Automatic::config();
}


//manual.h
#include "calibration.h"
class Manual : public Calibration {
public:
void calibrate();
}


//manual.cpp 
Manual::Manual(){}

void Manual::calibrate(){
....
}

void Calibrate::init(){
 Manual::calibrate();
}
Run Code Online (Sandbox Code Playgroud)

我如何更正呼叫Manual::calibrateAutomatic::config来自Calibrate::init()

我试过了:

void Calibrate::init(){ …
Run Code Online (Sandbox Code Playgroud)

c++

4
推荐指数
1
解决办法
3万
查看次数

如何在 Tkinter 中调整按钮的大小?

我已经工作了python一个星期,Tkinter工作时间甚至更少,如果我的问题很典型,我很抱歉。


我想为示波器编写一个简单的 GUI。我遇到了如何使按钮的大小适合其他按钮的大小的问题。这是我所达到的目标(屏幕截图)。 在此输入图像描述 您可能会注意到triggerhorizontal按钮的大小小于所有channel组。那么如何使他们的尺寸与团体尺寸完全channel一致。这是我的一段代码。

class StartPage(tk.Frame):

def __init__(self, parent, controller):
    tk.Frame.__init__(self, parent)
    self.controller = controller
    startLabel = tk.Label(self,
                          text="Start page")
    startLabel.pack(side="top")

    quitGroup = tk.Frame(self)
    quitGroup.pack(side="bottom")
    quitButton = tk.Button(quitGroup, text="Quit",
                           command=quit,
                           bg="pink")
    quitButton.grid(pady=10)

    channelGroup = tk.Frame(self)
    channelGroup.pack(side=tk.LEFT)
    chLabel = tk.Label(channelGroup,
                       text="Channel group")
    chLabel.grid(pady=10)

    ch1Button = tk.Button(channelGroup, text="CH1 Settings",
                          command=lambda: controller.show_frame("CH1"))
    ch1Button.grid(row=1, column=0)

    ch2Button = tk.Button(channelGroup, text="CH2 Settings",
                          command=lambda: controller.show_frame("CH2"))
    ch2Button.grid(row=2, column=0)

    ch3Button = tk.Button(channelGroup, text="CH3 Settings",
                          command=lambda: controller.show_frame("CH3")) …
Run Code Online (Sandbox Code Playgroud)

python tkinter

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

函数中默认的`const vector <int>&id`参数

我有以下功能:

double Fitter(double EBeam, vector<KFParticle>
&MeasParticle, vector<TLorentzVector> &RecoParticle,
const vector<int> &id) {  
   do something
}
Run Code Online (Sandbox Code Playgroud)

但有时我不想提供最后一个参数(id向量).我需要这样的东西:

double Fitter( ..., const vector<int> &id = empty_vector )
Run Code Online (Sandbox Code Playgroud)

但我不想创建一些静态向量.

c++ vector

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

'000000q'是什么意思?

我正在用这本教科书学习x86_64汇编语言(yasm).在那里,我遇到了以下定义文件访问标志的行:

O_RDONLY        equ    000000q
O_WRONLY        equ    000001q
O_RDWR          equ    000002q
Run Code Online (Sandbox Code Playgroud)

问题是他们的价值观是什么意思?什么q代表什么?

assembly x86-64 nasm yasm

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

如何知道在 Tkinter.Frame 中有多少行/列

预赛

在我的Tkinter应用程序中,我经常需要将列Tkinter.Framegrid_columnconfigure方法对齐。我使用简单的统一方法在框架中放置小部件:

  1. 我有从类继承的定制框架Tkinter.Frame
  2. 我将小部件放置在与grid管理器一起定制的框架中,并且每列都具有相同的权重

代码

定制框架

这是我定制的框架之一的代码。SFrame只是一个Tkinter.Frame带有样式的类包装器:

class GroupFrame( SFrame ) :
    """
        This class represents a frame with a title at the top
    """
    def __init__( self, parent, style, title, **kwargs ) :
        SFrame.__init__( self, parent, style, **kwargs )
        self.config( borderwidth=5, relief=tk.SUNKEN )

        self.style = style
        self.title = title.upper()

        self.CreateFrames()
        self.FillFrames()


    def CreateFrames( self ) :
        self.titleFrame = SFrame( self, self.style ) 
        self.titleFrame.pack( side="top", pady=10 …
Run Code Online (Sandbox Code Playgroud)

python tkinter

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

当ttk.Button处于活动状态时,如何更改其前景色?

我有一个ttk.Button我想改变的颜色。

我通过以下方式做到了:

Style().configure('gray.TButton', foreground='black', background='gray')              
backButton = Button(self.bottomFrame, text="Back",
                       command=lambda: controller.ShowFrame("StartPage"),  
                       style='gray.TButton')      
backButton.pack(side='left')
Run Code Online (Sandbox Code Playgroud)

而且效果很好(截图):

在此输入图像描述

但如果这个小部件处于活动模式(鼠标光标在其中),它看起来很糟糕。背景变成白色,因此文本变得不可见。

问题:如何在活动模式下更改文本颜色?

编辑1:在此之后:

class BackSubmit(MainFrame):                             

def __init__(self, parent, controller, title):       
  MainFrame.__init__(self, parent, controller, title)

  Style().configure('gray.TButton', foreground='white', background='gray')                  
  backButton = Button(self.bottomFrame, text="Back",
                      command=lambda: controller.ShowFrame("StartPage"),
                      style='gray.TButton')          
  backButton.bind( '<Enter>', self.UpdateFgInAcSt )                                         
  backButton.pack(side='left')                       

  Style().configure('blue.TButton', foreground='blue', background='light blue')
  submitButton = Button(self.bottomFrame,            
                        text="Submit settings",   
                        command=lambda: self.submitSettings(),
                        style='blue.TButton')        
  submitButton.pack(side=RIGHT)                      

def submitSettings(self):                            
  raise NotImplementedError("Subframe must implement abstract method")

def UpdateFgInAcSt(self, event):                     
  backButton.configure(activeforeground='gray')   
Run Code Online (Sandbox Code Playgroud)

我收到错误:

backButton.configure(activeforeground='gray') NameError: global name 'backButton' …

python colors ttk

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

关于ulp(x)的定义(最后一位的单位)

我遇到过以下 Ulp 定义(来自本文1 ,定义5):

在此输入图像描述

尽管有一些不清楚的地方(定义中的线性这个词是否意味着两个 FP(浮点)数字之间这个函数是线性的——不是一个常数),据我了解,两个实数之间的ulp 距离与之间的 FP 数量成正比这些数字。然而,从该定义的下一个用法(在那篇文章中)来看,它毫无意义:

在此输入图像描述

这里x是实数,X是FP数,RN( x )表示x四舍五入到最接近的FP数。上述不等式两边的量具有不同的性质:LHS 是实数(可以任意小),RHS 是离散的(xX之间的 FP 数的数量)。

更新

假设精度为0.1。FP 为 0, 0.1, 0.2, ... 取x =0.06 且X =0.3。那么I(x) =0.6, I(X) =3 我们有 | xx | = 0.24,ulp 距离为 2.4,因此满足不等式,但x舍入到最接近的 FP 的结论并不成立。

我错过了什么吗?


  1. 关于 ulp(x) 的定义,Jean-Michel Muller

floating-point precision numerical-methods

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