Question
I trying to run this code But I am getting this error: --mycode-- --main.cpp-- #include algorithm_utils.h #include #include #include #include #include using namespace std; int
I trying to run this code
But I am getting this error:
--mycode--
--main.cpp--
#include "algorithm_utils.h" #include #include
using namespace std;
int main () { std::vector
// set some values: for (int i=1; i
// TODO: use replace_if to replace all even numbers with 0 std::replace_if (vectorOfInts.begin(), vectorOfInts.end(), IsEven, 0);
std::cout ::iterator it=vectorOfInts.begin(); it!=vectorOfInts.end(); ++it) std::cout
std::vector // TODO: use replace_if to replace all even numbers with 0 using a function object or functor // The functor needs to do the output of each replaced element. std::for_each(vectorOfInts2.begin(), vectorOfInts2.end(), ReplaceEvenAndOutput()); std::cout ::iterator it=vectorOfInts2.begin(); it!=vectorOfInts2.end(); ++it) std::cout --algorithm_utils.h-- #ifndef LESSON_9_STL_ALGORITHM_REPLACE_IF_ALGORITHM_UTILS_H #define LESSON_9_STL_ALGORITHM_REPLACE_IF_ALGORITHM_UTILS_H #include // TODO: put the prototype of the function to test for even here bool IsEven (int i); // TODO: put the declaration of the functor class that tests for even values here class ReplaceEvenAndOutput{ public: void operator()(int& elem); }; #endif --algorithm_utils.cpp-- #include "algorithm_utils.h" // TODO: put the definition of the function to test for even here bool IsEven (int i){ return ((i%2)==0); } // TODO: put the definitions for the functor here class ReplaceEvenAndOutput{ public: void operator()(int& elem) { if (elem % 2 == 0) { std::cout algorithm_utils.cpp:10:7: error: redefinition of 'class ReplaceEvenAndoutput' 10 I class ReplaceEvenAndOutput \{ In file included from algorithm_utils.cpp:1: algorithm-utils.h:11:7: note: previous definition of 'class ReplaceEvenAndoutput' 11 I class ReplaceEvenAndoutput \{
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started