您好,我正在尝试在我的班级内创建一个新结构,但我认为某种公共和私有范围存在问题。
typedef struct Currency
{
Currency(Coin *coin, Currency *next, int _position) : _coin(coin), _next(next), _position(0) {}
Currency() : _next(NULL), _position(0) {}
Coin *_coin;
Currency *_next;
int _position;
};
那是我在课堂公共部分内的结构,当我尝试这样做时
if(location <= exit)
{
start = location + 11;
begin = response.find("label", start);
end = begin - start - 3;
findStrings(start, end, s, &response);
curr._next = new Currency();
}
它表示 new Currency() 调用的预期类型说明符。有什么我遗漏的东西还是不应该以这种方式使用结构?
类交换{公共:
typedef struct Badge
{
Badge(std::string id, Badge next, Badge prev, int length) : _id(id), _next(&next), _prev(&prev), _position(length) {}
Badge() : _id(""), _next(NULL), _prev(NULL), _position(0) {}
std::string _id;
Badge *_next;
Badge *_prev;
int _position;
};
typedef struct Currency
{
Currency(Coin *coin, Currency *next, int _position) : _coin(coin), _next(next), _position(0) {}
Currency() : _next(NULL), _position(0) {}
Coin *_coin;
Currency *_next;
int _position;
};
/* constructor and destructor */
Exchange();
Exchange(std::string str);
~Exchange();
/* Assignment operator */
Exchange& operator =(const Exchange& copyExchange);
void parseTradePairs(Currency curr, const std::string response, int begin, int exit);
private:
std::string _exch;
Currency *_currencies;
Badge *_ident;
};
万一
^ 在类头中
Exchange::Exchange()
{
_exch = "";
}
Exchange::Exchange(std::string str)
{
_exch = str;
_ident = new Badge;
_currencies = new Currency;
std::string pair;
std::string response;
CURL *curl;
getTradePairs(curl, response);
int exit = response.find_last_of("marketid");
parseTradePairs(*_currencies, response, 0, exit);
}
void parseTradePairs(Exchange::Currency curr, std::string response, int begin, int exit)
{
int start;
int end;
string s;
int location = response.find("marketid", begin);
if(location <= exit)
{
start = location + 11;
begin = response.find("label", start);
end = begin - start - 3;
findStrings(start, end, s, &response);
curr._next = new Currency();
}
}
^ 显然是在 cpp 类中。