gpt4 book ai didi

C++:使用STL vector有什么错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:27:45 26 4
gpt4 key购买 nike

我使用的是 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 使用针对问题的测试代码来编译您的代码。确保您提供的代码符合问题陈述中的要求。

关于C++:使用STL vector有什么错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8951244/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com