小编Ces*_*ian的帖子

'std :: string'没有名为front的成员

#include <iostream>
#include <string>
using namespace std;

string buff, resultstr, userstr;

string convert(const string& userstr)
{
    buff = userstr.front();
    resultstr = userstr;
    resultstr.front() = '_';
    resultstr = resultstr + buff + "ay";
    return resultstr;
}
Run Code Online (Sandbox Code Playgroud)

这是我的代码,我使用QT Creator 3.1.0和GCC 4.9.0作为编译器,这给了我:

in function 'std::string convert(const string& userstr)':
'const string' has no member named 'front'
'std::string' has no member named 'front'
Run Code Online (Sandbox Code Playgroud)

我搜索了一下,在一个较旧的问题中发现如果你的编译器不支持C++ 11会发生这种情况,但GCC应该支持自4.8以来.难道我做错了什么?我是C++的新手,所以我不会感到惊讶.

注意:我跳过了"main"函数,因为它仅用于加载QT GUI.

string qt gcc function c++11

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

从类中为类创建动态变量

对于上下文,我正在使用RPG中的库存系统,我正在使用python代码进行原型设计.

我不明白的是如何为项目的每个实例创建单独的变量而不手动声明它们.举个简短​​的例子:

class Player(object):
    def __init__(self):
        self.Items = {}

class Item(object):
    def __init__(self):
        self.Equipped = 0

class Leather_Pants(Item):
    def __init__(self):
        #What do i place here?
    def Pick_Up(self, owner):
        owner.Items[self.???] = self #What do i then put at "???"
    def Equip(self):
        self.Equipped = 1
PC = Player()
#Below this line is what i want to be able to do
Leather_Pants(NPC) #<-Create a unique instance in an NPC's inventory
Leather_Pants(Treasure_Chest5) #Spawn a unique instance of pants in a treasure chest
Leather_Pants1.Pick_Up(PC) #Place …
Run Code Online (Sandbox Code Playgroud)

python variables class dynamic-data python-2.7

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

标签 统计

c++11 ×1

class ×1

dynamic-data ×1

function ×1

gcc ×1

python ×1

python-2.7 ×1

qt ×1

string ×1

variables ×1