I got the below compile errors. Any idea what could be wrong here?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <iostream>
#include <algorithm>
#include <vector>
class MergeNames
{
public:
static std::vector<std::string> unique_names(const std::vector<std::string>& names1, const std::vector<std::string>& names2)
{
//throw std::logic_error("Waiting to be implemented");
std::vector<std::string> vector_unique;
vector_unique.insert(vector_unique.end(), names1.begin(), names1.end());
vector_unique.insert(vector_unique.end(), names2.begin(), names2.end());
std::sort(vector_unique.begin(), vector_unique.end());
auto last = std::unique(vector_unique.begin(), vector_unique.end());
vector_unique.erase(last, vector_unique.end());
return vector_unique;
}
};
#ifndef RunTests
int main()
{
std::vector<std::string> names1 = {"Ava", "Emma", "Olivia"};
std::vector<std::string> names2 = {"Olivia", "Sophia", "Emma"};
std::vector<std::string> result = MergeNames::unique_names(names1, names2);
for(auto element : result)
{
std::cout << element << ' '; // should print Ava Emma Olivia Sophia
}
}
#endif
| |
Error running solution, see below
Compiler error output:
Main.cpp:13:
./ProblemTest.cpp:19:43: error: use of undeclared identifier 'unique_names'; did you mean 'MergeNames::unique_names'?
std::vector<std::string> actual = unique_names(vector1, vector2);
^~~~~~~~~~~~
MergeNames::unique_names
./Problem.cpp:17:37: note: 'MergeNames::unique_names' declared here
static std::vector<std::string> unique_names(const std::vector<std::string>& names1, const std::vector<std::string>& names2)
^
Main.cpp:13:
./ProblemTest.cpp:39:43: error: use of undeclared identifier 'unique_names'; did you mean 'MergeNames::unique_names'?
std::vector<std::string> actual = unique_names(vector1, vector2);
^~~~~~~~~~~~
MergeNames::unique_names
./Problem.cpp:17:37: note: 'MergeNames::unique_names' declared here
static std::vector<std::string> unique_names(const std::vector<std::string>& names1, const std::vector<std::string>& names2)
^
Main.cpp:13:
./ProblemTest.cpp:50:18: error: use of undeclared identifier 'unique_names'; did you mean 'MergeNames::unique_names'?
actual = unique_names(vector1, vector2);
^~~~~~~~~~~~
MergeNames::unique_names
./Problem.cpp:17:37: note: 'MergeNames::unique_names' declared here
static std::vector<std::string> unique_names(const std::vector<std::string>& names1, const std::vector<std::string>& names2)
^
Main.cpp:13:
./ProblemTest.cpp:70:43: error: use of undeclared identifier 'unique_names'; did you mean 'MergeNames::unique_names'?
std::vector<std::string> actual = unique_names(vector1, vector2);
^~~~~~~~~~~~
MergeNames::unique_names
./Problem.cpp:17:37: note: 'MergeNames::unique_names' declared here
static std::vector<std::string> unique_names(const std::vector<std::string>& names1, const std::vector<std::string>& names2)
^
Main.cpp:13:
./ProblemTest.cpp:81:18: error: use of undeclared identifier 'unique_names'; did you mean 'MergeNames::unique_names'?
actual = unique_names(vector1, vector2);
^~~~~~~~~~~~
MergeNames::unique_names
./Problem.cpp:17:37: note: 'MergeNames::unique_names' declared here
static std::vector<std::string> unique_names(const std::vector<std::string>& names1, const std::vector<std::string>& names2)
^
Main.cpp:13:
./ProblemTest.cpp:101:43: error: use of undeclared identifier 'unique_names'; did you mean 'MergeNames::unique_names'?
std::vector<std::string> actual = unique_names(vector1, vector2);
^~~~~~~~~~~~
MergeNames::unique_names
./Problem.cpp:17:37: note: 'MergeNames::unique_names' declared here
static std::vector<std::string> unique_names(const std::vector<std::string>& names1, const std::vector<std::string>& names2)
^
Main.cpp:13:
./ProblemTest.cpp:112:18: error: use of undeclared identifier 'unique_names'; did you mean 'MergeNames::unique_names'?
actual = unique_names(vector1, vector2);
^~~~~~~~~~~~
MergeNames::unique_names
./Problem.cpp:17:37: note: 'MergeNames::unique_names' declared here
static std::vector<std::string> unique_names(const std::vector<std::string>& names1, const std::vector<std::string>& names2)
^
7 errors generated.