I have a queue and I need to verify the input data type and handle the exception in case the data input isn't the same as the data type in the queue, how can I do this? MAIN.cpp
try {
cout << "Insert character: ";
cin >> ch;
prova.push(ch);
}
catch (wrong_insert& k) {
k.allert();
};
This is the push function:
template <class t>
void queue<t>::push(const t& entry)
{
if(*I need this condition*) throw wrong_insert();
if(empty())
{
head_insert(front_ptr, entry);
rear_ptr = front_ptr;
}
else
{
insert(rear_ptr, entry);
rear_ptr = rear_ptr->link();
}
++count;
cout << "Inserted!" << endl;
}
and this is the exception class:
class wrong_insert
{
public:
wrong_insert() : message("Wrong data inserted!"){};
void allert(){ cout << message;};
private:
string message;
};