Измените std::unique_ptr
на std::unique_ptr
и добавьте виртуальный деструктор в Base
. Затем вы можете объявить массив объектов unique_ptr
так же, как вы объявляете массив указателей Base*
и std::move()
ваши существующие объекты std::unique_ptr
в массив.
Попробуйте это:
#include
#include
#include
using namespace std;
// Base is an abstract base class.
class Base {
private:
string myName; // Name of this person
public:
Base(string name) : myName(name) {}
virtual ~Base() {}
// A pure virtual function with a function body
virtual void hello() const {
cout << "Hello, my name is " << myName << ".";
}
};
class ServiceAgent : public Base {
public:
ServiceAgent(string name) : Base(name) {}
void hello() const override {
Base::hello();
cout << " I'm a customer service representative. How may I help you?" << endl;
}
};
class Student : public Base {
public:
enum category { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };
category personType;
Student(string name, category pType) : Base(name), personType(pType) {}
void hello() const override {
Base::hello();
cout << " " << enumToString(personType) << endl;
}
string enumToString (category c) const
{
switch (c) {
case FRESHMAN:
return "I'm a Freshman";
case SOPHOMORE:
return "I'm a Sophomore";
case JUNIOR:
return "I'm a Junior";
case SENIOR:
return "I'm a Senior";
}
return "";
}
};
class CSStudent : public Student {
public:
CSStudent(string name, Student::category type) : Student(name, type) {}
void hello() const override {
Student::hello();
cout << "I'm a computer science major." << endl;
}
};
class BUSStudent : public Student {
public :
BUSStudent(string name, Student::category type) : Student(name, type) {}
void hello() const override {
Student::hello();
cout << "I'm a business major." << endl;
}
};
int main() {
std::unique_ptr agentJack(new ServiceAgent("Jacqueline"));
std::unique_ptr studentJack(new Student("Jackson", Student::FRESHMAN));
std::unique_ptr studentCSS(new CSStudent("Jack", Student::SOPHOMORE));
std::unique_ptr studentBus1(new BUSStudent("Jacky", Student::JUNIOR));
std::unique_ptr studentBus2(new BUSStudent("Joyce", Student::SENIOR));
std::unique_ptr arr[] = { std::move(agentJack), std::move(studentJack), std::move(studentCSS), std::move(studentBus1), std::move(studentBus2) };
for (auto &var : arr)
{
var->hello();
cout << "-----" << endl;
}
return 0;
}
Да, точно так (принятие Вас правильно аутентифицировало Ваших пользователей и установило их роли соответственно). Проверьте статью MSDN: http://msdn.microsoft.com/en-us/library/8d82143t (По сравнению с 71) .aspx
Да, роли, пользователи и глаголы принимают разделенные значения запятой.
да, можно добавить n роли как этот.
Если Вы предпочитаете, Вы можете также:
<allow roles="admin"/>
<allow roles="admin1"/>
<deny users="*"/>