小编Tho*_*son的帖子

C++ 0x嵌套初始化列表

我想使用C++ 0x新的初始化列表功能来初始化std :: vector,其中包含我正在处理的新API的编译时定义的项目数.像这样的东西:

template<int n>
std::initializer_list<std::string> duplicate(std::string s) {
  // return s duplicated n times
  return { s, s, s };
}

std::vector<std::string> v = { "foo",  duplicate<3>("bar") };
Run Code Online (Sandbox Code Playgroud)

你知道怎么做到这一点吗?它甚至可能吗?我知道我将需要使用TMP和递归来构建重复字符串列表,并最终通过常量(例如,枚举)以某种方式访问​​它.但似乎我甚至无法像这样嵌套初始化列表.

c++ initializer-list template-meta-programming c++11

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

TypeError:'NoneType'对象不可迭代

我得到"类型错误:'NoneType’对象不是可迭代的"上线"公司名称,monthAverage,costPerTon,TOTALCOST = displayCost(公司名称,monthAverage,costPerTon,TOTALCOST)",我不能为我的生命弄清楚为什么.

抱歉,我似乎无法正确格式化...

4-25-11最终项目,全球垃圾计划

主要功能

def main():

    #intialize variables
    endProgram = 'no'
    companyName = 'NONAME'

    #call to input company name
    companyName = inputName(companyName)

    #start 'end program' while loop
    while endProgram == 'no':

        #initializes variables
        companyName = 'NONAME'
        monthAverage = 0
        costPerTon = 0
        totalCost = 0
        yearTotal = 0

        #call to input company name
        companyName = inputName(companyName)

        #call to get the tonnage
        yearTotal, monthAverage = getTonnage(yearTotal, monthAverage)

        #call to calculate the cost
        monthAverage, costPerTon, totalCost, yearTotal = calculateCost(monthAverage, costPerTon, …
Run Code Online (Sandbox Code Playgroud)

python

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