1

我正在尝试为 Topcoder 问题提交用 C++ 编写的解决方案。

该代码正在运行我的本地机器(Ubuntu 12.04 Linux,gcc)

但是在编译(Topcoder Compiler)时出现以下错误。

编译错误:

In file included from top level:11:
Your class or method was improperly declared: In function ‘std::string _wrapper::thunk(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> > > >, std::string)’:
Your class or method was improperly declared:20003: error: invalid use of incomplete type ‘struct UserName’
end of your submission:10030: error: forward declaration of ‘struct UserName’

以下是我的代码:

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>

using namespace std;

class Username {

    public:
        string newMember(vector <string> existingNames, string newName) {
            int i, j, result = 0;
            for(i=0;i<existingNames.size();i++) {
                if(newName == existingNames[i]) {
                    result = 1;
                }
            }
            if(result == 1) {
                for(i=1;i<50;i++) {
                    result = 0;
                    string newUsername = newName;
                    stringstream k;
                    k << i;
                    newUsername += k.str();
                    for(j=0; j<existingNames.size(); j++) {
                        if(newUsername == existingNames[j]) {
                            result = 1;
                        }
                    }
                    if (result == 0) {
                        return(newUsername);
                    }
                }
            } else {
                return(newName);
            }
        }
};

有人可以请指出我实际出错的地方吗?

4

0 回答 0