C Board  

Go Back   C Board > Community Boards > Contests Board

Reply
 
LinkBack Thread Tools Display Modes
Old 07-20-2007, 10:50 AM   #1
Massively Single Player
 
AverageSoftware's Avatar
 
Join Date: May 2007
Location: Buffalo, NY
Posts: 141
Ten Errors

The following program contains, to the best of my knowledge, ten errors.

Can you find them all? Some are easy, some are hard, and there are many things that only appear to be errors that exist to fool the unwary.

Rules:
Any error that occurs more than once is one error. For example, an error in the declaration of a function would be repeated on its definition. This is one error, not two.

Errors exist in isolation. That is, if class Dog has an error in its definition, that does not make further use of class Dog an error.

Errors must be explained, not merely located. Responses of "line 12" or quoted text with red highlights are not accepted. Clearly state what is wrong.

I'm only interested in language errors, not logical errors. If the error prevents compilation or linking, it is an error. If it crashes the program at run time, is it not an error.

No assumptions are to made about anything. The only information you have is the code itself.

I have tried very hard to eliminate typos and unintended errors. If someone locates either of these, I will fix the code to correct the unintended mistake.

There are three files in the program, and here they are:

classes.h
Code:
1	#ifndef CLASSES_H
2	#define CLASSES_H
3
4	export template <typename t>
5	class Doodad : private t
6	{
7	public:
8		Doodad();
9		~Doodad();
10		template<int x> virtual void DoIt();
11
12	private:
13		virtual void MakeItSo() = 0;
14
15		t::Thingy Thingy1;
16	};
17
18	template <typename t, template <typename> typename cont>
19	class Archive
20	{
21	public:
22		Archive();
23		~Archive();
24
25	private:
26		cont<t> Data;
27	};
28
29	class TBase
30	{
31	public:
32		struct Thingy
33		{
34			int x;
35			int y;
36			int z;
37		};
38
39		TBase();
40		~TBase();
41		void operator ->* (void (TBase::*f)());
42		void operator .* (void (TBase::*f)());
43
44	private:
45		Thingy T;
46	};
47
48	class Widget : public Doodad<TBase>
49	{
50	private:
51		void MakeItSo() ??< ??>
52	};
53
54	int operator () (Thingy T, int x, int y, int z)
55	{
56		T.x = x;
57		T.y = y;
58		T.z = z;
59
60		return 0;
61	}
62
63	#endif
64

classes.cpp
Code:
1	#include "classes.h"
2
3	template <typename t>
4	Doodad<t>::Doodad()
5	{
6		Thingy1.x = 1;
7	}
8
9	template <typename t>
10	Doodad<t>::~Doodad()
11	{
12		Thingy1.y = 6;
13	}
14
15	template <typename t>
16	template <int x>
17	void Doodad<t>::DoIt()
18	{
19		int *p = &x;
20
21		Thingy1.x *= *p;
22	}
23
24	template <typename t>
25	void Doodad<t>::MakeItSo()
26	{
27		Thingy1.z = 11;
28	}
29
30	template <typename t, template <typename> typename cont>
31	Archive<t, cont>::Archive()
32	{
33		Data.clear();
34	}
35
36	template <typename t, template <typename> typename cont>
37	Archive<t, cont>::~Archive()
38	{
39		Data.destroy();
40	}
41
42	TBase::TBase()
43	{
44		T.x = 1;
45		T.y = T.x * 100;
46		T.z = T.x * T.y;
47	}
48
49	TBase::~TBase()
50	{
51		T.z = 0;
52	}
53
54	void TBase::operator ->* (void (TBase::*f)())
55	{
56		(this->*f)();
57	}
58
59	void TBase::operator .* (void (TBase::*f)())
60	{
61		((*this).*f)();
62	}
63
main.cpp
Code:
1	#include <iostream>
2	#include "classes.h"
3
4	namespace BAM = std;
5
6	template <double d>
7	double PassThrough()
8	{
9		return d;
10	}
11
12	template <int x, int y = 0>
13	int Math()
14	try
15	{
16		return x - y;
17	}
18	catch (...)
19	{
20		BAM::cout << "Critical subtraction failure!" << BAM::endl;
21	}
22
23	union Combo
24	{
25		TBase TB;
26		short tiny;
27		char moretinier;
28	};
29
30	void main()
31	{
32		Widget *W = new Widget;
33
34		try
35		{
36	TheTop:
37			float lotsOfFloats[20];
38
39			if (W and lotsOfFloats[5] or Math<10, 5>())
40			{
41				8[lotsOfFloats] = 4.5;
42
43				goto TheTop;
44			}
45
46			goto Cleanup;
47		}
48		catch (...)
49		{
50	Cleanup:
51			delete W;
52		}
53	}
54
__________________
There is no greater sign that a computing technology is worthless than the association of the word "solution" with it.
AverageSoftware is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
global namespace errors stubaan C++ Programming 9 04-02-2008 03:11 PM
Unknown Errors in simple program neandrake C++ Programming 16 04-06-2004 02:57 PM
Stupid compiler errors ChrisEacrett C++ Programming 9 11-30-2003 05:44 PM
Help me with these errors... :-( major_small C++ Programming 6 09-07-2003 08:18 PM
errors in class(urgent) ayesha C++ Programming 2 11-10-2001 06:51 PM


All times are GMT -6. The time now is 01:00 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22