小编pLO*_*eGG的帖子

Visual Studio 2010上的程序编译,但VS 2015上没有

几年前,我正在使用VS 2010用C++编写软件,当我想编译它时,它会向我显示错误.我确切地知道,如果你使用VS 2010它仍然有效,但我的工作只有2015年.

我创建了一个简单的代码来向您显示错误,它涉及一个模板类tab1D,它从vector中引用并重新定义运算符,如"()".以下是简化的代码:

简单主要:

#include <iostream>
#include "memory_tab.h"
using namespace std;

int main() {
    cout << "Hello" << endl;
    tab1D<int> t (2);
    cout << "Initialization works fine" << endl;
    cout << t[1] << endl;
    cout << "Bracket operator works fine" << endl;
    cout << t(1) << endl; // this line calls parenthesis operator which is overwritten in memory_tab.h. It does not compile.
    cout << "Error C3867 & C2100" << endl;
    int a;
    cin >> a;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

memory_tab.h: …

c++ stl visual-studio-2010 visual-studio-2015

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

Python argparse多个metavar名称

我正在使用argparsepython库。在某些时候,我使用一个名为param2 的参数,称为参数:一个键和一个值。我使用的代码行如下:

parser.add_argument("-p", "--param", nargs=2, action="append", 
                    help="key and value for query", 
                    type=str, metavar="key value"
                    )
Run Code Online (Sandbox Code Playgroud)

出问题了,当我致电帮助时,它显示如下:

optional arguments:
    -h, --help            show this help message and exit
    -p key value key value, --param key value key value
                          key and value for query parameters
Run Code Online (Sandbox Code Playgroud)

名称“键值”重复两次。我尝试使用列表和生成器,但是我发现的唯一方法是创建一个包含不同值的小类,并在要求__str__这样时产生它们:

class Meta:
    def __init__(self, iterable):
        self.gene = itertools.cycle(iterable)

    def __str__(self):
        return self.gene.__next__()
Run Code Online (Sandbox Code Playgroud)

我这样打电话add_argument

parser.add_argument("-p", "--param", nargs=2, action="append", 
                    help="key and value for query parameters",
                    type=str, metavar=Meta(["key", "value"])
                    )
Run Code Online (Sandbox Code Playgroud)

并且它正确显示:

-p …
Run Code Online (Sandbox Code Playgroud)

python argparse

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