C++ Quiz question

Pages: 12
No-one wants to use a friend? :(
Why don't *YOU* use it?
You can't modify the class ;p
closed account (3hM2Nwbp)
I cheat.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <jni.h>

JNIEXPORT class MyClass
{
public:
	// PUBLIC AREA MUST BE BLANK

protected:
	// PROTECTED AREA MUST BE BLANK

private:
	// PRIVATE AREA IS ALLOWED for Print functioin only

	virtual void Print()
	{
		cout << "MyClass" << endl;
	}
};

1
2
3
4
5
6
7
8
9
10
11
public class MyClass
{
    private native void Print();

    public static void main(String[] args)
    {
        System.loadLibrary("MyClass");
        MyClass mc = new MyClass();
        mc.Print();
    }
}


That's using the JNI interface through Java. Apparently, friends are no longer the only ones that want to touch your privates. Think of Java as the sex-offender next-door.

Disclaimer: I didn't compile / test the above code, but it's similar to a job that I'm working on now.
Last edited on
Clever! Yet another banned solution for this quiz: http://www.cplusplus.com/forum/lounge/59315/#msg320359
As I'm not smart enough to code-cheat my way around it, I'll apply my methodology of assumption-based cheating:

Assumption 1: "Can't change this class!" is enforced by keeping the class definition in a different file so the tester knows it hasn't been changed.
Assumption 2: Since the one and only rule is strictly enforced by assumption 1, the tester only needs to confirm the output to check the correctness.

Solution:
1
2
3
4
int main() {
    std::cout << "You haxxor..." << std::endl;
    return 0;
}
Luc Lieber,
The solution to Qestion which you posted has already been solved by Sloppy9.

there is one more to go posted by L B.
Hahaha Gaminic - I thought it was implicitly disallowed because the idea was to call the print function in the class I gave rather than just do what it would have done. Clever and unique, but not the intended solution ;)
closed account (3hM2Nwbp)
@codekiddy

I know, my solution was intended to be humorous, but seems to have failed.
Topic archived. No new replies allowed.
Pages: 12