#include <iostream>
#include <vector>
#include <string>
class Npc
{
public:
std::string npc_arr;
};
class Guard :public Npc
{
public :
std::string npc_arr;
Guard(std::string npc_arr);
};
Guard::Guard(std::string npc_arr)
{
this->npc_arr = npc_arr;
}
class Civil :public Npc
{
public:
Civil(std::string npc_arr);
};
Civil::Civil(std::string npc_arr)
{
this->npc_arr = npc_arr;
}
class InfoShower :public Npc
{
public:
static void showInfo(std::vector<Npc*> npc_arr);
};
void InfoShower::showInfo(std::vector<Npc*> npc_arr)
{
std::cout << "in the village";
for (int i = 0; i < npc_arr.size(); ++i)
{
std::cout << npc_arr[i] << ",";
}
std::cout << "There is." << std::endl;
}
int main()
{
std::vector<Npc*> npc_arr;
npc_arr.push_back ("guard");
npc_arr.push_back ("citizen");
InfoShower::showInfo(npc_arr);
return 0;
}
Is there anything I can do about the price of garbage?
c++표준
#include <iostream>
#include <vector>
#include <string>
class Npc
{
public:
std::string npc_arr;
};
class Guard :public Npc
{
public :
Guard(std::string npc_arr);
};
Guard::Guard(std::string npc_arr)
{
this->npc_arr = npc_arr;
}
class Civil :public Npc
{
public:
Civil(std::string npc_arr);
};
Civil::Civil(std::string npc_arr)
{
this->npc_arr = npc_arr;
}
class InfoShower
{
public:
static void showInfo(std::vector<Npc*> npc_arr);
};
void InfoShower::showInfo(std::vector<Npc*> npc_arr)
{
std::cout << "in the village";
for (int i = 0; i < npc_arr.size(); ++i)
{
std::cout << npc_arr[i]->npc_arr << ",";
}
std::cout << "There is." << std::endl;
}
int main()
{
std::vector<Npc*> npc_arr;
npc_arr.push_back ("guard");
npc_arr.push_back ("citizen");
InfoShower::showInfo(npc_arr);
return 0;
}
© 2024 OneMinuteCode. All rights reserved.