#include <iostream>
using namespace std;
typedef enum {
NotEqual,
Less,
Equal,
Greater
} CompareResult;
template <typename _T>
struct CF {
typedef CompareResult (*CompareFunc)(const _T&, const _T&);
};
template <typename _T>
class avl_tree
{
protected:
typename CF<_T>::CompareFunc m_cf;
public:
avl_tree(typename CF<_T>::CompareFunc func) : m_cf(func), m_tree(nullptr) {}
};
CompareResult compare_int(const int& item1, const int& item2)
{
if (item1 < item2)
return Less;
if (item1 > item2)
return Greater;
return Equal;
}
int main()
{
avl_tree<int> int_tree(compare_int);
return 0;
}
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
int main()
{
int l, a, b, c;
l = getchar();
char k;
switch(l)
{
case 'a':
printf ("Input task: ");
scanf ("%d%c%d", &a, &k, &b);
if (k == '+') {
c = a + b;
printf ("%d%c%d = %d", a, k, b, c);
}
else if (k == '-') {
c = a - b;
printf ("%d%c%d = %d", a, k, b, c);
}
else if (k == '*') {
c = a * b;
printf ("%d%c%d = %d", a, k, b, c);
}
else if (k == '/') {
if (b == 0) {
printf ("Error.");
exit (1);
}
c = a / b;
printf ("%d%c%d = %d", a, k, b, c);
}
break;
case 'b':
printf ("Input task: ");
scanf ("%d%c%d", &a, &k, &b);
if (k == '+') {
c = a + b;
printf ("%d", c);
}
else if (k == '-') {
c = a - b;
printf ("%d", c);
}
else if (k == '*') {
c = a * b;
printf ("%d", c);
}
else if (k == '/') {
if (b == 0) {
printf ("Error.");
exit (1);
}
c = a / b;
printf ("%d", c);
}
break;
}
return 0;
}
int a = 0;
#include <iostream>
#include <string>
using namespace std;
inline void error(const string& msg) {
throw msg.c_str();
}
inline void error(const char* msg = nullptr) {
throw msg;
}
void func2()
{
error("Just error.");
}
void func()
{
func2();
error(); // Just return to main()
}
int main()
{
while (true) {
try {
func();
}
catch (const char* msg) {
if (msg != nullptr)
cerr << "Error: " << msg << endl;
}
}
return 0;
}
#include <iostream>
using namespace std;
typedef enum {
Key1 = 1,
Key2 = 2,
Key4 = 4,
Key8 = 8
} Key;
void func(uint32_t keys)
{
if (keys & 1)
cout << "Key1 ";
if (keys & 2)
cout << "Key2 ";
if (keys & 4)
cout << "Key4 ";
if (keys & 8)
cout << "Key8 ";
cout << endl;
}
int main()
{
func(Key1 | Key4 | Key8);
return 0;
}