/*Infinity Bottles of Beer on the Wall in C++

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA

#include <iostream.h>

int main(void)
	int foo;
                cout << endl;
                cout << "Infinity bottles of beer on the wall!" << endl;
                cout << "Infinity bottles of beer," << endl;
                cout << "Take one down, pass it around." << endl;
                cout << "Infinity bottles of beer!" << endl;
        return 0;

No, no, that's no good. First of all, it's complete nonsense, and second, where is your sense of object orientation, man?

#include <iostream.h>

class InfiniteBeer {
		InfiniteBeer() {
			while( 1 )
				cout << "Infinity bottles of"
					" beer on the wall!"
					"\nInfinity bottles"
					" of beer,\nTake one"
					" down, pass it around"
					".\nInfinity bottles"
					" of beer!\n\n";

int main() {
	InfiniteBeer object;
	return 0;

See, why use C++ if you're not going to take full advantage of it? And I don't even know why you bothered with that fancy GPL header...

All of the examples so far do the job, I'll admit. But, what about us non-beer-drinkers? Fortunately, wielding the almighty power of C++, it's not too difficult to make a good version that works with other types of beverages.

Note that this also allows minors to enjoy an infinite thirst-quenching experience without potentially breaking laws that may prohibit that kind of activity if it involved alcohol.

Also, I believe instead of "infinity bottles of" anything, it might be more correct to say an "infinite number of" something. But, hey, keeping with the way everyone else is doing it, I won't be the one to mess up the song. ;)

#include <iostream>
#include <string>

template <typename beverage_traits>
class InfiniteBeverage {
  InfiniteBeverage() {
    const string &name = beverage_traits::name();
    while (1) {
      std::cout << "Infinity bottles of " << name << " on the wall!\n"
                << "Infinity bottles of " << name << ",\n"
                << "Take one down, pass it around.\n"
                << "Infinity bottles of " << name << "!\n\n";

class Coke {
  static const string &name() const { return "Coke"; }

// provided for backward compatibility
class Beer {
  static const string &name() const { return "beer"; }

int main() {
  InfiniteBeverage<Coke> infiniteCoke;

Log in or register to write something here or to contact authors.