My Complaint about C++

This is not meant to be a gripe thread. This is merely to serve as a conduit between myself and getting a better understanding for what I'm confused about. I remember back when I was using eclipse in my high school CS class that using java was extremely easy and you could easily write some simple lines of code to make a simple box. With a little more ease, it wasn't hard to code some buttons that did some functions. What I'm curious is why if its so easy for java to do it, how come c++ can't? And if it can and I'm not aware, why is it that no one I talk to can help me with it? I feel as though if I could have my question answered, I could give back rather than have to gripe and gripe about this.
Java is a high level language with an overhead while C/C++ is not. In itself, C++ is just a language without knowledge of what is a keyboard, monitor, modem, mouse, etc. This means that C++ in itself is unable to display graphics, read keystrokes, etc. Libraries must be used for this, but you must remember that since C++ is used for different OS's then there are diffierent libraries.

So one library comes along and someone is not happy with it and creates a new one, usually building on the previous one. The end result is a new library that is (usually) easier to use and with less code. But did you really shorten the code necessary to achieve the task? Not really. You are merely reusing existing code.

Well, that is in essence what Java does. Java provides a runtime library (per OS) that does many things in the background for you so you can write simple programs. They are hardly magical, though, as the end result is pretty much the same: At some point someone must have coded Java itself, and most likely they did it in C or C++.
How come there isn't a simple library that I can use that lets me just specify dimensions for a box? Or a line of code that allows me to create a button that, if clicked, will call a function somewhere in my program, and then print back out to the box?
Maybe there is. I don't know every single library out there. But you must remember that if you are looking for one, you must take into account the operating system and whether it is a console program or a windowed program.

For example, wxWidgets simplifies Windows programming for windowed programs quite a bit but I am unsure if that's what you are looking for as you haven't mentioned your requirements.
sounds like qt is a library perfect for you. it has a very nice framework, and it is pretty powerfull. it is a framework that allows you to make gui programs.
If you're using WIN32, you can just use CreateWindow() or CreateWindowEx() for this.

ref:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632679(v=vs.85).aspx

For a button use:
1
2
3
4
5
6
7
8
9
CreateWindow(L"button",                    // We're making a button
    L"Cancel",                             // This is what the button will say.
    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, // styles
    50, 100,                               // X and Y position (in pixels)
    150, 30,                               // Width and Height
    hWnd,                                  // Handle to the parent window
    (HMENU) ID_BUTTON1,                    // enum'd identifier for this button, it's used to identify the source of the message when your parent window gets the code.
    NULL, NULL                             // some optional stuff here.
); 
Last edited on
The point is that java comes with a gui library while C++ doesn't.

When you've done all the necessary actions to involve the gui library (like qt or wxwidgets) then it's as easy as it is with Java.

The library binding mechanism is just very inconvenient because it's rather poorly conceived
GTK+ is pretty easy to use. There are also project templates for GTK+ in codeblocks for linux. Then you can also incorporate clutter, cairo and cogl.
Would it simplify a lot of stuff if I just narrowed it down to solely Windows OS's? As in, no linux, no mac os's, just windows.
Nope, cross platform API's are generally easier to use than their platform specific counterparts. The reasons for going platform specific usually boil down to performance/memory limitations in one way or another.
Last edited on
What if I told you that the application I wanted to make was really really really simple? As in really simple.
A "really really simple" Qt application:
1
2
3
4
5
6
7
8
9
10
#include <QApplication>
#include <QPushButton>
int main(int argc,char** argv)
{
    QApplication app(argc,argv);
    QPushButton helloButton("Hello World!");
    helloButton.resize(80,20);
    helloButton.show();
    return app.exec();
}


If you use Qt Designer, you don't even need to write any code for this.

Would it simplify a lot of stuff if I just narrowed it down to solely Windows OS's? As in, no linux, no mac os's, just windows.

Besides Qt, there is also C++Builder, which relies on the VCL. It is Windows-only.
Like I said, this is a small very uncomplicated application that I want to make. Its basically a timer. You hit a button, it calls my timer function, creates a timer, then calls another function that displays the time remaining. The only "complicated" part in it I might see is right now, as a console app, you can only create one timer at a time.
You can create as many as you want, there's no fundamental difference between a console application and a GUI application. Besides, you just said you only need one.
Actually, the way its set up, no I can't create more than one. Once its created a single timer, the console locks up and starts cout'ing the time remaining for that timer. And unless I break out of that by some keystroke, I can't make more than one timer.
And how exactly do your create your "timer"?
A GUI is not magically able to do things the console cannot. If you appear to be able to do something with a GUI that the console simply cannot do, that's because the GUI library is hiding things from you. Things like threads.
Last edited on
Here's my timer program.

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <string>
using namespace std;

#include "Timer.h"
#include "TimerManager.h"

int main()
{
	cout << "Press ENTER to continue...";
	cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );

	cout << "Correct syntax is as follows: " << endl << "ob, tb, or, tr, drag, baron" << endl;

	Timer startTime; // STARTING TIME WHEN TIMER IS INITIALIZED
	Timer timer;
	TimerManager timeClock; 
	int c1 = 0;	int c2 = 0;
	int tS = 0;
	bool timed; // stores a bool value to check the timer progress

	char choice;
	do
	{
		cout << "Timer: ";
		cin >> timer.TimerName;
		if((timer.TimerName == "q") || (timer.TimerName == "quit"))
			choice = 'n';
		else
		{
			startTime.GetTime(); // Gets the time when timer gets called
			startTime.CurrTimePrint(); // Prints the time stored in the startTime object
			timer.SpawnTimer(timer);
	
			timer.min = timer.min + startTime.min;
			timer.sec = timer.sec + startTime.sec;

			timed = timeClock.timeCompare(startTime, timer, c1, c2, tS);
			while(!timed)
			{
				startTime.GetTime();
				timed = timeClock.timeCompare(startTime, timer, c1, c2, tS);
			}
			cout << timer.TimerName << " has expired." << endl;
	
			cout << "Another timer? ";
			cin >> choice;
			if(choice == 'y')
			{
				c1 = 0;	c2 = 0;	tS = 0;
				startTime.min = 0; startTime.sec = 0;
				timer.min = 0; timer.sec = 0; timer.TimerName = "";
			}
		}
	} while(choice == 'y');

	return 0;
}


timer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef TIMERH
#define TIMERH

#include <string>
#include <iomanip>

using namespace std;

class Timer
{
public:
	int hour, min, sec;
	string TimerName;
	Timer();
	Timer(int h, int m, int s);
	void CurrTimePrint();
	void GetTime();
	void SpawnTimer(Timer &t);
	//void AddTime(Timer, Timer);
};

#endif 


timer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <iostream>
#include "Timer.h"
using namespace std;

Timer::Timer() // default constructor
{
	hour = 0;
	min = 0;
	sec = 0;
}

Timer::Timer(int h, int m, int s) // specialized constructor
{
	hour = h;
	min = m;
	sec = s;
}

void Timer::CurrTimePrint() // Prints out time.
{
	cout << hour << ":";
	cout << setw(2) << setfill( '0' ) << min;
	cout << "." << setw(2) << setfill( '0' ) << sec;
	cout << endl;
}

void Timer::GetTime() // Gets the time and stores it in an object
{
	time_t rawtime;
	struct tm * timeinfo;

	time ( &rawtime );
	timeinfo = localtime ( &rawtime );

	hour = timeinfo -> tm_hour;
	min = timeinfo -> tm_min;
	sec = timeinfo -> tm_sec;
}

void Timer::SpawnTimer(Timer &timer) // Passes by reference a timer and gets its data needed
{
//////////////////////////////////////////////////////////////////////////////////////
	if((timer.TimerName == "ob") || (timer.TimerName == "OB"))
	{
		timer.TimerName = "Blue Buff: Ours";
		//cout << "STARTED BLUE BUFF: OURS" << endl;
		timer.min = 4;
		timer.sec = 58;
		//grab the amount of time for a blue buff
		//make sure it saves that spawn is OUR and print that where needed
		//send the time to the add method
	}
//////////////////////////////////////////////////////////////////////////////////////
	else if((timer.TimerName == "tb") || (timer.TimerName == "TB"))
	{
		timer.TimerName = "Blue Buff: Theirs";
		//cout << "STARTED BLUE BUFF: THEIRS" << endl;
		timer.min = 4;
		timer.sec = 58;
		//grab the amount of time for a blue buff
		//make sure it saves that spawn is THEIRS and print that where needed
		//send the time to the add method
	}
//////////////////////////////////////////////////////////////////////////////////////
	else if((timer.TimerName == "or") || (timer.TimerName == "OR"))
	{
		timer.TimerName = "Red Buff: Ours";
		//cout << "STARTED RED BUFF: OURS" << endl;
		timer.min = 4;
		timer.sec = 58;
		//grab the amount of time for a red buff
		//make sure it saves that spawn is OUR and print that where needed
		//send the time to the add method
	}
//////////////////////////////////////////////////////////////////////////////////////
	else if((timer.TimerName == "tr") || (timer.TimerName == "TR"))
	{
		timer.TimerName = "Red Buff: Theirs"; 
		//cout << "STARTED RED BUFF: THEIRS" << endl;
		timer.min = 4;
		timer.sec = 58;
		//grab the amount of time for a red buff
		//make sure it saves that spawn is THEIRS and print that where needed
		//send the time to the add method
	}
//////////////////////////////////////////////////////////////////////////////////////
	else if((timer.TimerName == "drag") || (timer.TimerName == "DRAG"))
	{
		timer.TimerName = "Dragon";
		//cout << "STARTED DRAGON" << endl;
		timer.min = 5;
		timer.sec = 58;
		//grab the amount of time for dragon
	}
//////////////////////////////////////////////////////////////////////////////////////
	else if((timer.TimerName == "baron") || (timer.TimerName == "BARON"))
	{
		timer.TimerName = "Baron";
		//cout << "STARTED BARON" << endl;
		timer.min = 6;
		timer.sec = 58;
		//grab the amount of time for baron
	}
//////////////////////////////////////////////////////////////////////////////////////
	else if((timer.TimerName == "test"))// TEST CASE
	{
		//cout << "test" << endl;
		timer.min = 1;
		timer.sec = 15;
	}
}

// timer method gets current time
// timer method that checks for what spawn timer needed
// timer method adds spawn time to current time
// timer method compares current time with spawn time
// timer method that prints to screen timer expires
// timer method that prints out remaining time (i.e 1 minute left, 30 seconds out) 
....Continued from above.

timermanager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include "TimerManager.h"
using namespace std;

TimerManager::TimerManager()
{
	//Forgot to do something with this.
}

bool TimerManager::timeCompare(Timer current, Timer goalTime, int &c1, int &c2, int &tS)
{
///////////////////////////////////////////////////////////////
// CHECKS THE TIMES TO SEE IF TIMER HAS EXPIRED
	current.GetTime();
	int minuteLeft, secondLeft; // temp variables to hold time differences
	secondLeft = goalTime.sec - current.sec;
	minuteLeft = goalTime.min - current.min;
	if((minuteLeft == 0) && (secondLeft == 0))
		return true;
///////////////////////////////////////////////////////////////
// USED TO KEEP TIME CONSTRAINTS PRINTED NORMAL (I.E prevents printing 1:60)
	if(secondLeft < 0) // if secondLeft is less than zero. converts to fix time holes
	{
		if(minuteLeft > 0)
		{
			int tempSec = 60;
			minuteLeft--;
			secondLeft = tempSec + secondLeft;
		}
		else if(minuteLeft > 1)
		{
			secondLeft = 60 + secondLeft;
		}
	}
	else if(secondLeft > 60) // if secondLeft is greater than 60. converts to fix time holes
	{
		minuteLeft++;
		secondLeft = secondLeft - 60;
	}
	else if(secondLeft == 60) // if secondLeft is 60, prevents 
	{
		secondLeft = 0;
		minuteLeft++;
	}
/////////////////////////////////////////////////////////////
// REPEAT PRINT CHECK / ALSO CONVERTS SINGLE DIGIT SECONDS TO :0x, x = second
	if((tS != secondLeft))
	{
		if((secondLeft < 10) && (secondLeft >= 0)) // ex. 0:1 into 0:00
		{
			cout << minuteLeft << ":0" << secondLeft << endl;
		}
		else
			cout << minuteLeft << ":" << secondLeft << endl;
	}
////////////////////////////////////////////////////////////////////////////////////
// WARNING TREES
////////////////////////////////////////////////////////////////////////////////////
// ONE MINUTE WARNING TREE
	if((minuteLeft == 1) && (secondLeft == 0))
	{
		if(c1 != 1)
		{
			cout << "ONE MINUTE WARNING" << endl;
			c1++;
		}
	}
///////////////////////////////////////////////////////////////
// THIRTY SECOND WARNING TREE
	if((minuteLeft == 0) && (secondLeft == 30))
	{
		if(c2 != 1)
		{
			cout << "30 SECOND WARNING" << endl;
			c2++;
		}
	}
///////////////////////////////////////////////////////////////
// ZERO TIME CHECK
	if((minuteLeft == 0) && (secondLeft == 0))
	{
		return true;
	}
///////////////////////////////////////////////////////////////
		tS = secondLeft; // REFERENCE TO MAIN
		return false;
///////////////////////////////////////////////////////////////
}

// This would work by having it check/update all initialized timers and check if any of them
// are currently close to any pertinent print times(i.e. 1 minute out, 30 seconds out). This would
// then take them and see about storing some sort of bool or possibly returning the string associated
// with the given timer object. 


timermanager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef TIMERMANAGER_H
#define TIMERMANAGER_H

#include <string>
using namespace std;

#include "Timer.h"

class TimerManager
{
private:

public:
	Timer a, b;
	string timerName;
	TimerManager();
	TimerManager(int, int, int);
	bool timeCompare(Timer, Timer, int&, int&, int&);
	void timerWarning(Timer, Timer);
};

#endif 
Topic archived. No new replies allowed.