int main() { Person jane("Jane Doe", 37, 64, 115, true); Person john("John Smith", 87, 70, 180, false); Person noone; // Can't touch these values; they're private. Uncomment these lines // to see the compiler messages. //strcpy(noone.name, "Davy Jones"); //noone.age = 99; // Check the output again, with the new default constructor char ident[1000]; jane.tostring(ident); printf("Jane ==> %s\n", ident); john.tostring(ident); printf("John ==> %s\n", ident); noone.tostring(ident); printf("noone==> %s\n", ident); return 0; }
int main() { Person jane("Jane Doe", 37, 64, 115, true); Person john("John Smith", 87, 70, 180, false); // Now we can use the default constructor and initialize individual // members separately. Person noone; strcpy(noone.name, "Davy Jones"); noone.age = 99; // Note that we haven't initialized everything; check the output! char ident[1000]; jane.tostring(ident); printf("Jane ==> %s\n", ident); john.tostring(ident); printf("John ==> %s\n", ident); noone.tostring(ident); printf("noone ==> %s\n", ident); return 0; }
int greater(min_pq m, int a, int b) { int (*jane)(const void *a, const void *b) = (m->compare); void *srb = m->items[a]; void *cro = m->items[b]; return jane(srb, cro); }
TEST_CASE test_concurrent_list() { stdString fred("fred"); stdString freddy("freddy"); stdString jane("jane"); stdString janet("janet"); stdString bob("bob"); ConcurrentList<stdString> subscribers; TEST(subscribers.isEmpty() == true); TEST(subscribers.size() == 0); TEST(subscribers.removeIfFound(&bob) == false); subscribers.add(&fred); TEST(subscribers.isEmpty() == false); TEST(subscribers.size() == 1); subscribers.add(&freddy); TEST(subscribers.isEmpty() == false); TEST(subscribers.size() == 2); subscribers.add(&jane); TEST(subscribers.isEmpty() == false); TEST(subscribers.size() == 3); subscribers.add(&janet); TEST(subscribers.isEmpty() == false); TEST(subscribers.size() == 4); TEST(subscribers.removeIfFound(&bob) == false); // This test assumes a certain order in which // elements are added to the list, // which could change with different implementations // of the ConcurrentList. COMMENT("Simple Iteration"); ConcurrentListIterator<stdString> s(subscribers.iterator()); TEST(*s.next() == "fred"); TEST(*s.next() == "freddy"); TEST(*s.next() == "jane"); TEST(*s.next() == "janet"); TEST(s.next() == 0); TEST(s.next() == 0); TEST(s.next() == 0); TEST(s.next() == 0); COMMENT("Iteration where 'fred' is removed while iterator is on it"); // Start over: Position on first entry, "fred" s = subscribers.iterator(); // Remove element, ... subscribers.remove(&fred); // but iterator was already on the element, so you still get it: TEST(*s.next() == "fred"); TEST(*s.next() == "freddy"); TEST(*s.next() == "jane"); TEST(*s.next() == "janet"); TEST(s.next() == 0); TEST(s.next() == 0); COMMENT("Iteration where 'fred' is gone, but 'bob' was added."); COMMENT("Then add 'fred' again while iterating."); subscribers.add(&bob); s = subscribers.iterator(); TEST(*s.next() == "bob"); TEST(*s.next() == "freddy"); subscribers.add(&fred); TEST(*s.next() == "jane"); TEST(*s.next() == "janet"); TEST(*s.next() == "fred"); TEST(s.next() == 0); TEST(s.next() == 0); TEST_OK; }