小编Tar*_*ama的帖子

覆盖Python Tkinter中的默认选项卡行为

我正在使用Tkinter编写Python应用程序来管理我的GUI.

我有一个文本输入框,我试图实现一个自动完成功能,它将绑定到Tab键.

我已将Tab键绑定到我的输入框,但是当我按Tab键时,程序会尝试在GUI元素之间循环.

如何覆盖此默认行为,以便GUI仅在按键上执行指定的命令?

谢谢

python user-interface tkinter

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

Rvalue和Lvalue参考

我有一个函数printInt,如下所示.

void printInt(const int& a)
{
    cout<<a<<endl;
}
Run Code Online (Sandbox Code Playgroud)

当我使用以下参数调用函数时

int a=5;
printInt(a);
printInt(5);
Run Code Online (Sandbox Code Playgroud)

它完美地运作.但是当我将函数定义更改为

void printInt(int& a)
{
    cout<<a<<endl;
}
Run Code Online (Sandbox Code Playgroud)

这给通话带来了错误printInt(5).现在我的问题是为什么const int&是左值和左值引用,而int&只是左值引用.据我所知,int&&是一个右值参考.那么单个&可以如何引用右值参考?

总结一下我的问题:

  1. 左值参考参数

    void printInt(int& a)
    {
        cout<<a<<endl;
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. Rvalue参考参数

    void printInt(int&& a)
    {
        cout<<a<<endl;
    }    
    
    Run Code Online (Sandbox Code Playgroud)
  3. 左值和左值.但怎么样?

    void printInt(const int& a)
    {
        cout<<a<<endl;
    }
    
    Run Code Online (Sandbox Code Playgroud)

c++ c++11

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

基于元组值排序矢量

我有以下数据结构,

typedef vector< tuple<int,int,int> > vector_tuple;
Run Code Online (Sandbox Code Playgroud)

在矢量我存储 tuple<value,count,position>

我想根据计数对矢量进行排序,如果计数相同则基于位置对矢量进行排序.

structure ordering
{
  bool ordering()(....)
  {
    return /// ?
  }

};
int main()
{ 
    std::vector<int> v1{1,1,1,6,6,5,4,4,5,5,5};
    std::vector<int> v2(v1);
    vector_tuple vt;
    std::tuple<int,int,int> t1;
    std::vector<int>::iterator iter;
    int sizev=v1.size();
    for(int i=0; i < sizev ; i++)
    {
         auto countnu = count(begin(v2),end(v2),v1[i]);  
         if(countnu > 0)
         {
           v2.erase(std::remove(begin(v2),end(v2),v1[i]),end(v2));
           auto t = std::make_tuple(v1[i], countnu, i);
           vt.push_back(t);
         }
     }
     sort(begin(vt),end(vt),ordering(get<1>vt); // I need to sort based on count and if count is same, sort based on position.


     for …
Run Code Online (Sandbox Code Playgroud)

c++ stl

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

SFINAE模板参数推断失败

当我编译这段代码时:

#include <type_traits>

template <typename T>
void do_stuff(std::enable_if_t<std::is_integral<T>::value, T> &t) {}

template <typename T>
void do_stuff(std::enable_if_t<std::is_class<T>::value, T> &t) {}

int main() {
    int i = 1;
    do_stuff(i);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

GCC说:

37325975.cpp: In function ‘int main()’:
37325975.cpp:11:15: error: no matching function for call to ‘do_stuff(int&)’
     do_stuff(i);
               ^
37325975.cpp:4:6: note: candidate: template<class T> void do_stuff(std::enable_if_t<std::is_integral<_Tp>::value, T>&)
 void do_stuff(std::enable_if_t<std::is_integral<T>::value, T> &t) {}
      ^
37325975.cpp:4:6: note:   template argument deduction/substitution failed:
37325975.cpp:11:15: note:   couldn't deduce template parameter ‘T’
     do_stuff(i);
               ^
37325975.cpp:7:6: note: candidate: template<class …
Run Code Online (Sandbox Code Playgroud)

c++ templates sfinae

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

DOMDocument :: loadHTML()中的实体中的意外结束标记p错误

为什么我会收到此代码的警告?

$content ='<p>
 <a href="http://www.we.com/1000">text </a>
 text 
 <a href="http://www.we.com/2345">text </a>
  text 
</p>

<p>text</p>

<p>
  <table border="1" cellpadding="0" cellspacing="0" dir="rtl"> 
      <tbody> 
          <tr> 
              <td>text </td> 
              <td>text </td> 
              <td>text </td> 
          </tr> 
          <tr> 
              <td>text </td> 
              <td>text </td> 
              <td>text </td> 
          </tr> 
      </tbody> 
  </table>
</p>';

$doc = new DOMDocument('1.0', 'UTF-8');
$doc->loadHTML($content);
Run Code Online (Sandbox Code Playgroud)

警告是:

警告:DOMDocument :: loadHTML():意外结束标记:实体中的p,第2213行的/home/admin/domains/we.com/public_html/refresh/lib/core.php中的第25行<p> <a href =“ http://www.we.com/1000 ” > 文本 </a>文本<a href=" http://www.we.com/2345">文本 </a>文本</ p> < p> text </ p> <p> </ p> <table border =“ 1” cellpadding =“ 0” cellspacing =“ 0” dir …

php compiler-errors domdocument

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

没有明显的原因,继续在c ++中的指针代码上出错

所以我正在尝试使用指针,因为我对C++编程很陌生,错误p1未在此范围内声明不断出现我不知道我在互联网最深处的角落搜索无济于事.

#include <iostream>
using namespace std;

int main()
{ 
    int num1 = 8;
    *p1 = &num1;

    cout << "VALUE:" <<  *p1 <<endl;
    cout << "adress" << &num1 <<endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ pointers

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

if else和#if #else #endif之间的区别

我在if/ else#if/ #else/ #endif构造之间感到困惑.

  1. 它们之间有什么区别?
  2. 我应该在哪些特定情况下使用它们?

c c++ macrodef

-6
推荐指数
3
解决办法
3968
查看次数

将五个整数与if,else if语句进行比较

我需要比较五个整数并找到最大和最小的整数.我需要通过仅使用if和else语句来解决它,我不能使用找到max,min输入的数组或特定函数.

这是我到目前为止所做的:

int n1, n2, n3, n4, n5, biggest,smallest;
n1=biggest;


cout << "Enter the five numbers: ";

cin >> n1 >> n2 >> n3 >> n4 >> n5 ;

if ((n2>=n1) && (n2>=n3) && (n2>=n4) && (n2>=n5)) {
    n2 = biggest;
}
else if ((n3>=n4) && (n3>=n5)) {
    n3 = biggest ;
}
else if (n4>=n5) {
    n4 = biggest ;
}
else {
    n5 = biggest ;
}

cout << biggest ;
Run Code Online (Sandbox Code Playgroud)

为什么输出0而不是最大数?

c++

-13
推荐指数
1
解决办法
282
查看次数

这些实现会导致内存泄漏吗?

以下几种情况会导致内存泄漏吗?如果是,我该如何解决问题?我应该在Base类(即Structure* var)中使用指针并在析构函数中删除它吗?

如果情况 2 不会导致内存泄漏,会发生什么Structure(0,0)?它是立即创建并被销毁还是会发生其他事情?

情况1 :

struct Structure
{
    int a;
    int b;
    Structure() { a=1; b=2; }
    Structure(int num1, int num2) : a(num1), b(num2){}
};

class Base
{
    private:
        Structure var;
    public: 
        Base(Structure structure)
        {
            var = structure;
        }
};

class Derived : public Base
{
    public:
        Derived(bool boolean) : Base(boolean ? *(new Structure(0,0)) : *(new Structure(10,10))){}
};

int main()
{
    Derived derived(true);
}
Run Code Online (Sandbox Code Playgroud)

案例2:

struct Structure
{
    int a;
    int b; …
Run Code Online (Sandbox Code Playgroud)

c++

-23
推荐指数
1
解决办法
388
查看次数