Category Archives: DLed

DLed’s works

C++ humor: a –do not modify the comments or format– horror code

executable at Ideone

#include <iostream>
#define B(l,a) __##l##E##__
#define _O_ ((1<<2>>1<<1)-2)
#define _h_ 7-3
#define _C_ (7/_h_)
#define _r_ ((1<<0)+0x00a/2+_C_)
#define _a_ ((1<<5)-_r_)
#define _p_ { void _(){} namespace
#define printf(_0_) squeak(_O_,B(LIN,!)-_a_); _
 
// this
// is weird
 
namespace _p_ {
void squeak(int,int who) {      switch (who) {
                case _O_: std::cout<<"quak"<<std::endl; break;
                case (_h_+_C_-2): std::cout<<"meow"<<std::endl; break;
                case _h_: std::cout<<"bow"<<std::endl; break;
                default: std::cout<<"blah"<<std::endl; break;
        };
}}
}
 
// do not review ...
 
int main()
{
        printf("hello\n");
        printf("this\n");
        printf("is\n");
        printf("not\n");
        printf("funny\n");
        printf("at all!\n");
        return 0;
}
 
//expected output:
//meow
//blah
//quak
//blah
//bow
//blah

 

On unwanted access to inner classes in C++11

#include <iostream>
#include <typeinfo>

class Outer {
private:
	class Inner {
	public:
		void Do() {
			std::cout<<"Do"<<std::endl;
		}
	};
private:
	Inner inner;
public:
	Inner& Get() {
		return inner;
	}
};

int main()
{
	Outer O;
	// err: private Outer::Inner
    // Outer::Inner& x=O.Get(); x.Do();
    auto& x=O.Get();
    x.Do(); // ok
    std::cout << typeid(x).name() << std::endl;  
    O.Get().Do(); // ok
    return 0;
}