我使用的是topcoder C++编译器,尽管此代码在Linux gcc中运行良好,但topcoder编译器却出现此错误:
your code did not compile:
errors compiling:
Your class or method was improperly declared: In function
‘std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > _wrapper::thunk(std::string)’:
Your class or method was improperly declared:20034:
error: conversion from ‘void’ to non-scalar type
‘std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >,
std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >’ requested
这是标记错误的代码段:
class BinaryCode {
public:
static int get_digit(char c)
{
return (c-'0');
}
void decode(string decd)
{
int i;
std::vector <int> decoded(decd.size());
std::transform(decd.begin(), decd.end(), decoded.begin(), &get_digit);
int length=decoded.size();
这是topcoder问题描述:
Definition Class:BinaryCode
Method:decode
Parameters:string
Returns:vector <string>
Method signature:
vector <string> decode(string message)
(确保您的方法是公开的)
最佳答案
您的方法签名是:
void decode(string decd)
应该:
vector <string> decode(string message)
TopCoder使用测试代码来编译问题的代码。确保您提供的代码符合问题陈述中的要求。