Skip to content

Instantly share code, notes, and snippets.

@kaworu
Created September 8, 2017 14:08
Show Gist options
  • Save kaworu/33fd113f0a8e0e481bb936b8cc2205f4 to your computer and use it in GitHub Desktop.
Save kaworu/33fd113f0a8e0e481bb936b8cc2205f4 to your computer and use it in GitHub Desktop.
#include <iostream>
class Rack {
public:
Rack(int i): m_i(i)
{ }
int geti()
{
return m_i;
}
protected:
int m_i;
};
void
do_something_with_racks(Rack *list[], size_t len)
{
for (size_t i = 0; i < len; i++)
std::cout << list[i]->geti() << std::endl;
}
int
main(int argc, char **argv)
{
Rack one(1);
Rack answer(42);
Rack vegeta(9001);
Rack *list[] = {&one, &answer, &vegeta};
do_something_with_racks(list, (sizeof(list) / sizeof(*list)));
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment