View Full Version : Programming Language
pcbrainbuster
04-08-2007, 11:59 PM
Hello again :),
These days i've been wondering to myself if I should learn propper computer programming languages and am asking you lot on what you think I should and if you do think I should try to learn one then please also reccomend one of the following languages and a compiler... -
Java
C++
Thanks :)...
pcbrainbuster
04-09-2007, 12:01 AM
And please also reccomend sites, for tutorials and examples :)
Woah Nelly, get a decent grasp on Javascript first :)
After that I'd recommend you move onto Python before taking the step up to Java, then on to C++. It's one heck of a step down in terms of hand-holding to go from Javascript to C++, I think you'd find the change quite a shock if you step over all the possible intermediate stages.
pcbrainbuster
04-09-2007, 12:12 AM
Makes sense... (I hate your first line though !!! :))...
But I think my grasp is OK though, I gues I'll be checkin out python while then but what compiler shall I use?...
Python is an interpreted language, not compiled. If you run a UNIX-based OS, chances are it's already installed; if not, you can get it from http://www.python.org/.
mburt
04-09-2007, 12:31 AM
Yes, it is a fairly big step from JavaScript to C++. In fact, I recommend you learn Java first, the C, then C++. But do as the master says, learn Python first :).
pcbrainbuster
04-09-2007, 01:26 AM
Anyway I'm on the current site and I would like to know if I'm starting off at a good position -
http://docs.python.org/tut/node4.html
pcbrainbuster
04-09-2007, 01:37 AM
Actually I have decided that I hate python... The followin reasons are why -
1) Python is not good for creating interfaces as far as I know
2) And more...
I'm going to start off at Java...
edit//- Can't find a Java (windows) compiler... I would appreciate it if someone can help with this :)
mburt
04-09-2007, 01:59 AM
1) Python is not good for creating interfaces as far as I know
Python is equally as good as any other language.
edit//- Can't find a Java (windows) compiler... I would appreciate it if someone can help with this
Err...
http://java.sun.com
That's the only place to get a compiler.
tech_support
04-09-2007, 04:52 AM
But I think my grasp is OK though, I gues I'll be checkin out python while then but what compiler shall I use?...
Aren't you a bit optimistic for saying that you're OK?
shachi
04-09-2007, 10:05 AM
pcbrainbuster: I suggest you stop jumping like an over excited(unstable) atom which might break at any time. And python is an extremely powerful language(including you can build interfaces with it), it can build extremely powerful interfaces while using very performance, even programs like blender(http://blender3d.org/) is made with python and you say, it's not good to build interfaces? Which world are you in?
http://java.sun.com
That's the only place to get a compiler.Not so... there are numerous third-party compilers and runtimes available.
Python has bindings for (among others) wxWidgets, a very powerful cross-platform GUI toolkit. "And more..." isn't a reason :) Personally, I prefer the tutorial at diveintopython.org (http://www.diveintopython.org/). However, almost any tutorials on Python (and most other languages, too) will start by teaching you the language, not the use of extras like wxPython or, in Java's case, Swing or AWT, which allow you to build graphical interfaces.
Have patience, young grasshopper!
mburt
04-09-2007, 12:19 PM
Python has bindings for (among others) wxWidgets, a very powerful cross-platform GUI toolkit.
Also makes it much easier to create high-level programs.
Yes, it has platform-independent layers for things like sockets and threading, as well.
mburt
04-09-2007, 12:36 PM
I would dread to re-learn Win32 API. *wince.
Almost pointless for me to use wxWidgets with C++, now that I've learned the hard way (which, by the way is working out wonderfully :)).
If I had my time back, I would've definitely used wxWidgets to program C++.
Almost pointless for me to use wxWidgets with C++, now that I've learned the hard wayNot at all. You just try porting one of those applications to a different platform :) The good thing about wxWidgets (apart from being one heck of a lot faster to code than raw Win32/X API) is that you can port a "pure" wxWidgets application, using only wxWidgets and the C++ standard libraries, with nothing more than a recompile.
mburt
04-09-2007, 01:01 PM
You just try porting one of those applications to a different platform :)
I don't have another platform :).
Also, I installed wxWidgets 2.8.2, and CodeBlocks keeps reading 2.6.2, I even changed the system variables (that's what it said to do).
I'm not going to install 2.6.2 either, seeings 2.8.2 took the entire day to download (dial-up).
Argh, no, that's like saying "why should I make my Web pages work in Firefox? I don't use Firefox" :p Portability is always a good thing.
pcbrainbuster
04-09-2007, 01:43 PM
Well OK if you lot say I should stick with Python for know (wasn't my fault for thinking its not good at creating interfaces but what I read I was gonna believe as I had no EXP)...
At the same time I will get more "grasp" on JavaScript...
pcbrainbuster
04-09-2007, 01:58 PM
Actually forget it... I'm gonna get perfect grasp on JavaScript and PHP before going into any language... :) (sorry for the whole lol)...
mburt
04-09-2007, 06:25 PM
Good idea.
PHP is probably closer to C then anything, so go for it.
Not really :) I'd say PHP was closer to Perl.
mburt
04-09-2007, 07:31 PM
But Perl was never suggested here, so I'm going to stay with what has already been said.
pcbrainbuster
04-09-2007, 10:28 PM
But first I will need to perfect some areas within JavaScript...
Like closures for one...
pcbrainbuster
05-14-2007, 12:31 PM
Sorry for that,I forgot about this thread...
Anyway my mind is set and I have decided to go for C++ no matter what, and I have a god compiler I trust and that is that, so now with the questions :) -
1) Am I correct saying that when you include a file your just inluding its contents?
2) What is meant by a library/nampespace?
edit-I can't find any site that is offering C++ GUI tutorials, please help.
Thanks.
mwinter
05-14-2007, 04:30 PM
Yes, it is a fairly big step from JavaScript to C++. In fact, I recommend you learn Java first, the C, then C++.
Don't consider C to be a stepping stone to C++. For a start, all of the other languages you mention are object-oriented, whereas C is procedural. The change in paradigm will not help someone, especially if they're inexperienced. Moreover, there are compatibility issues between C and C++ which someone might overlook as the two seem the same in many respects.
But first I will need to perfect some areas within JavaScript...
Like closures for one...
I wrote an article regarding closures which was moved to the tips and tutorials board. I've also explained closures elsewhere in this forum and on Usenet. Have a search. If you need help, feel free to start a new thread.
1) Am I correct saying that when you include a file your just inluding its contents?
The short answer: yes.
The #include directive is acted upon as part of the preprocessor phase of compilation, which also includes such things as conditional compilation and macro expansion. The preprocessor is used to create the input that the compiler will actually work upon.
When the #include directive is encountered, the preprocessor searches the list of include paths for the named file and replaces the directive with the contents. The different delimiters around the filename tend to imply alternate search locations: angle brackets usually indicate standard headers (the C run-time and standard template libraries, Win32 headers, etc.), whilst quotes signify user-defined headers (those present in "nearby" directories).
2) What is meant by a library/nampespace?
The two terms are separate.
A library is a collection of code, usually created with the intention of reusing it. The functions therein typically relate to one another in some way, but this doesn't have to be the case.
A namespace is a partition, if you will. Normally, two classes definitions with the same name will cause a compilation error as there is ambiguity between which one is supposed to be used.
class A {
public:
A() {}
};
class A {
public:
A() {}
};
int main() {
A a; // Which A?
return 0;
}
However, if each is defined within different namespaces, there is no confusion: by qualifying the class name with the namespace name, the compiler knows exactly which is which.
namespace Foo {
class A {
public:
A() {}
};
}
namespace Bar {
class A {
public:
A() {}
};
}
int main() {
Foo::A a; // Only one possible class
return 0;
}
I can't find any site that is offering C++ GUI tutorials, please help.
Why should there be? There is no standard GUI library for C++. You need to decide what interface you want to interact with, first. For cross-platform development you might want to look at the Qt or wxWidgets toolkits. Alternatively, you might want limit yourself to only one platform - for example, the Win32 API. I would recommend a toolkit, personally.
It's been a while since I've used C++ seriously so I may be completely wrong here, but as I remember it a semicolon is required after class definitions and the operator for accessing members of a namespace is ::, not .. Thus, the above example would become:
namespace Foo {
class A {
public:
A() {}
};
}
namespace Bar {
class A {
public:
A() {}
};
}
int main() {
Foo::A a; // Only one possible class
return 0;
}
mwinter
05-14-2007, 05:26 PM
It's been a while since I've used C++ seriously so I may be completely wrong here, but as I remember it a semicolon is required after class definitions and the operator for accessing members of a namespace is ::, not ..
Yes, you're quite right. How foolish...
Are you any good at decerning problems with makefiles, Twey?
pcbrainbuster
05-14-2007, 05:31 PM
I am completely lost, as I do not underdstand words like abiguty and some stuff about C++ PL you just said...
Please remember I am completely new to this and need you to explain a little more, though I REALLY appeciate it that you lot even bothered, so thanks!
Anyway more questions -
1) Is the namespace a predefined sort of library?
2) When I use cout to print my strings/numbers etc, do I enable myself to use that through the file iostream?
3) And by that GUI thing I meant that a far as any tutorial is going for me its teaching me how to write console programs, but I am not interested in console programs but rather ones with an interface possible to build if you know what I mean (most programs are windowed ones, thats what I am looking for)
Thanks alot guys I really appreciate your help !:)
Are you any good at decerning problems with makefiles, Twey?
Oh, I do hate it when people say things like that... it's impossible to tell whether I'll be able to discern it or not without looking at the problem :p
I do not underdstand words like abigutyhttp://www.dictionary.com/
and some stuff about C++ PL you just said...What "stuff" in particular?
1) Is the namespace a predefined sort of library?No. Once you understand Mike's post above, you'll understand this.
2) When I use cout to print my strings/numbers etc, do I enable myself to use that through the file iostream?Yes.
3) And by that GUI thing I meant that a far as any tutorial is going for me its teaching me how to write console programs, but I am not interested in console programs but rather ones with an interface possible to build if you know what I mean (most programs are windowed ones, thats what I am looking for)All C++ tutorials will, because whatever GUI library you choose will inevitably require you to have a good working knowledge of some of the more advanced concepts of the language in order to make good use of it.
mwinter
05-14-2007, 06:10 PM
I am completely lost, as I do not underdstand words like abiguty and some stuff about C++ PL you just said...
Well, you'll need to be specific when you don't understand something. We can't really predict what you will know and what you won't.
As for the definition of ambiguity (and any other unknown words), that's what a dictionary is for. :) Whilst we're on the subject, though, something is ambiguous if it can be interpreted in more than one way.
1) Is the namespace a predefined sort of library?
No. It is a "declarative region" in code, an area where things (classes, functions, etc.) can be declared - and defined.
I'm tempted to compare it to scope, for simplicity, but it's not really accurate and may be troublesome in the long run.
2) When I use cout to print my strings/numbers etc, do I enable myself to use that through the file iostream?
Yes. To reference the object, you'll need to qualify the identifier:
#include <iostream>
int main() {
std::cout << "Hello world!";
return 0;
}
There is another way - with a using declaration - but that's best avoided as it can make code less clear.
Are you any good at decerning problems with makefiles, Twey?
Oh, I do hate it when people say things like that... it's impossible to tell whether I'll be able to discern it or not without looking at the problem
If you know bugger all about makefiles, you could have replied no. :) I'll start another thread, rather than hijack this one.
pcbrainbuster
05-14-2007, 06:12 PM
No. Once you understand Mike's post above, you'll understand this.
That's the thing, I don't... The way the example is shown as if mwinter has defined the namespaces, but in my console programming knowlegde of its use I defined nothing and used this line -
using namespace std;
All C++ tutorials will, because whatever GUI library you choose will inevitably require you to have a good working knowledge of some of the more advanced concepts of the language in order to make good use of it.
I am a little confused hre but are you saying that I need to learn console programming?
edit-OK I have read his post and am lost at namespaces, are they necessary?, and also how are windowed programs made???
mwinter
05-14-2007, 06:39 PM
I'll start another thread, rather than hijack this one.
Never mind. I found the problem even though I'm sure I checked the variable declaration in question... :rolleyes:
The way the example is shown as if mwinter has defined the namespaces,
That's because I did to illustrate the concept.
If you're using code with namespaces involved, someone has to define them, even if you didn't.
but in my console programming knowlegde of its use I defined nothing and used this line -
What's your point? You asked what namespaces are, not how to use them. My code snippets were expository.
using namespace std;
As I wrote in my previous post, try to avoid the using declaration. Just qualify members of the namespace.
I am a little confused hre but are you saying that I need to learn console programming?
No, you need to learn the language. However, the simplicity of working with the console often means that it's the quickest way to learn as you don't complicate things by having to learn about the interface toolkit as well.
edit-OK I have read his post and am lost at namespaces, are they necessary?
Necessary, as in essential? No. PHP gets by without namespaces, but only barely. However, they are very useful and makes life a lot easier when working with existing code.
and also how are windowed programs made???
Depends on how you interact with the windowing system.
pcbrainbuster
05-14-2007, 06:56 PM
YES !, I think I understand what a namespace is -
its like functions in functions in javascript, am I right?
edit-Is there any pont of me learning console programming to start with?
mwinter
05-14-2007, 07:33 PM
[Namespaces are] like functions in functions in javascript, am I right?
Not exactly (it depends what aspect you're considering), which is why I didn't want to use scope as an analogy.
Namespaces change how declared entities are accessed. They separate bits of code into groups that can't interfere quite so simply with one another. You normally have to specify the namespace before accessing its members.
For example, given:
namespace foo {
int i = 0;
}
the code:
#include <iostream>
int main() {
std::cout << i;
}
will fail as there is no global variable, i. However,
#include <iostream>
int main() {
std::cout << foo::i;
}
will (outputting "0").
This prevents the members from clashing, as I illustrated in my first post.
As another example, consider:
int i = 0;
namespace foo {
int i = 1;
}
This snippet is legal as though both integers have the same name, they are declared in different declarative regions (namespaces).
In ECMAScript, if you want such a comparison, one could use objects:
var container = {i : 0, foo : {i : 1}};
Here, the object, container, contains all of the properties concerned. It has a property, i, with the value 0, and another property, foo, which is an object. This latter object has, in turn, its own property, i, with a value of 1.
Is there any pont of me learning console programming to start with?
As I wrote previously, it simplifies the process by allowing you to concentrate on the language, rather than other things like how to interact with a graphical interface. Though you'll want to do that eventually, its easier to take one thing at a time.
If you're serious about this, you need to appreciate that it will take time. Lots of time.
pcbrainbuster
05-14-2007, 07:42 PM
Lol, so would this work -
#include <iostream>
using namespace std;
namespace namespace1
{
int a = 1;
}
namespace namespace2
{
int a = 2;
}
int main ()
{
using namespace namespace1;
cout << a;
cout << namespace2::a;
}
Have I grasped the namespace concept (this is just an example of the meany ways of using namespaces)...
questions :
1) Why is the main function int main () for?
2) Can int main () be int main()
3) But int is used as a variable type, why is it a part of the main function's name?
mwinter
05-14-2007, 08:21 PM
Lol, so would this work -
A simple way to answer that sort of question is to compile and link the code, and run the resulting executable. :)
Yes, it works, however you don't return a value (specifically, an integer) from main.
Have I grasped the namespace concept (this is just an example of the meany ways of using namespaces)...
It seems so, but I was once told that the best way to show understanding is to try and explain the concept to someone else.
1) Why is the main function int main () for?
I assume you meant to write "What..." not "Why...".
The C++ Standard states:
A program shall contain a global function called main, which is the designated start of the program.
-- 3.6.1 Main function, ISO/IEC 14882:2003
In other words, it's the standard way to mark where to begin.
2) Can int main () be int main()
Yes. White space is generally insignificant, as in most programming languages. The only time it matters is when separating certain adjacent tokens, like type specifiers and the identifiers that follow them. Clearly,
intmain() {
/* ... */
}
can't be right.
3) But int is used as a variable type, why is it a part of the main function's name?
It isn't. It specifies the return type.
Just so you know, the main function has another form:
int main(int argc, char* argv[]) {
/* ... */
}
The first argument, argc, contains the number of arguments passed on the command line when starting the program. The second argument, argv, is an array of pointers to null-terminated character strings.
pcbrainbuster
05-14-2007, 08:57 PM
Thanks man, my learning of this PL won't work without you :)! -
So right now I am learning console programmng then I plan to go into an interface environment, is this a dangerous step (Is the structure of console programming different to that of GUI programming? So different that it may mess with me learning GUI programming?)...
There is a problem though, everytime I make a script for the console it gets executed and then shuts of straight away (I now why this happens but isn't there a way to pause the command prompt?)...
And you did ask how much I know and here it is -
I understand includes
I understand namespaces
I understand how to write
I understand how to perform simple calulations (eg +-*/)
I understand how to create lines (eg \n)
I understand int main as the first function to run
I understand all the types of variables (eg int, float, double etc)
What I need to know is -
How to perform advanced calculations
What is a class
How and why to use any other function
Setting time outs
(and more but can't think of 'em)
mwinter
05-14-2007, 09:25 PM
So right now I am learning console programmng then I plan to go into an interface environment, is this a dangerous step (Is the structure of console programming different to that of GUI programming? So different that it may mess with me learning GUI programming?)...
No. The most important thing, in my opinion, is the language first and foremost. Unless you actually understand how the language works, you can't really expect to succeed. However, I will point out that GUI use a different approach, but one that you should already be familiar with from browser scripting: event-driven programming.
There is a problem though, everytime I make a script for the console it gets executed and then shuts of straight away (I now why this happens but isn't there a way to pause the command prompt?)...
You could just prompt for input at the end of the program. For example,
#include <iostream>
int main() {
/* ... */
std::cout << "Press Return to exit...";
std::cin.get();
return 0;
}
A bit messy, but it'll work.
I understand all the types of variables (eg int, float, double etc)
Do you understand the limits of those primitive types. Also don't forget that arrays, pointers and user-defined types are also variable types.
How to perform advanced calculations
That's a little vague. What's an "advanced" calculation?
What is a class
A class is a user-defined type; a blueprint, if you will, of data and behaviour. Objects are created from classes. An OO primer will provide a more thorough description.
How and why to use any other function
I'm not sure what you mean.
Setting time outs
In what sense? Like setTimeout in browsers? That's a rather complex process.
pcbrainbuster
05-14-2007, 10:09 PM
You could just prompt for input at the end of the program. For example,
Code:
#include <iostream>
int main() {
/* ... */
std::cout << "Press Return to exit...";
std::cin.get();
return 0;
}A bit messy, but it'll work.
Never heard of cin or it's ,method get()... I will look it up though...
Do you understand the limits of those primitive types. Also don't forget that arrays, pointers and user-defined types are also variable types.
Yep, I do...
That's a little vague. What's an "advanced" calculation?
Things like square roots, powers/indicies...
I'm not sure what you mean.
More classes or functions, but as far as I am concerened that is not needed in console programming (am I right?)...
In what sense? Like setTimeout in browsers? That's a rather complex process.
Basically, yeah...
mburt
05-15-2007, 12:03 AM
Never heard of cin or it's ,method get()... I will look it up though...
cin is the way of interpreting input from the user. The get() method gathers cout data I believe (correct me).
Things like square roots, powers/indicies...Functions such as pow() and sqrt() can be found in <math>.
cin is the way of interpreting input from the user. The get() method gathers cout data I believe (correct me).Hm, I know what you mean, but that's not the best way of explaining it. Rather than thinking of the terminal as a single entity, rather picture it as two or three separate streams: cout and cerr (but cerr doesn't exist on Windows), output streams, and cin, an input stream. When you read from cin, you're reading from the input the user gives; the streams aren't actually connected in any way other than that in most terminals they're displayed or collected by the same window.
pcbrainbuster
05-15-2007, 06:52 AM
Thanks guys but I think I will go into other files later...
questions -
1) When you include a file and then compile your work do you create another file which can be avoided if you don't use includes but rather just put the file's contents into your code?
2) I am not sure about cin or the get() method, does cin simply pause the control prompt until a key is pressed and does get() simply collect all the cout data in the function and set it as the pause's text?Or does get() use the last writting cout before it as the pause's text?
1) When you include a file and then compile your work do you create another file which can be avoided if you don't use includes but rather just put the file's contents into your code?
Unless the included file isn't made by you, there will be no "other" files (no iostream.o what so ever will be created). And it's a bad (crazy?) idea to just put the file's contents into your file.
My math.h file contains 849 lines of code, and anyway, basicly every standard include file includes other files, so you'll end up with an enormously big file.
2) I am not sure about cin or the get() method, does cin simply pause the control prompt until a key is pressed and does get() simply collect all the cout data in the function and set it as the pause's text?Or does get() use the last writting cout before it as the pause's text?
cin is an input stream, it has nothing to do with cout or outprinted messages. Using cout is not just "writing stuff to console window" you are simply sending your text to a stream which can be read by other applications. If running on windows then cmd.exe is just a program which reads text from your application's output stream and shows it to the user.
Again cin is an input stream to which other applications can write text, and that's what cmd.exe does.
cin.get() requests text to be given via the input stream, get() with no arguments simply returns the "typed" character as an integer (similar to event.keyCode/event.which in javascript). While text is being read, the program is "paused", so it continues (exits) after you've submitted your input.
mwinter
05-15-2007, 07:29 PM
Never heard of cin or it's ,method get()... I will look it up though...
The object, cin, is one of the standard iostream objects like cout; there are eight in all. As has been written already, cin is an input stream: an instance of the std::istream class.
Do you understand the limits of those primitive types.
Yep, I do...
Care to prove it? The only reason why I ask is that lots of people get it wrong. For instance, consider the code below:
#include <iostream>
int main() {
long value = 0x7FFFFFFF;
std::cout << ++value;
return 0;
}
Without running this, tell me what value is written to the output stream, cout. This is a good, basic exercise for anyone using C++ (or C, for that matter).
More classes or functions, but as far as I am concerened that is not needed in console programming (am I right?)...
Additional classes and functions should be created as need dictates. If a console-based program suggests the use of an abstract data type, then design a class. If an algorithm can be decomposed into many distinct parts, create functions for each of them. The fact that you're using the console has no effect on the process of programming, only how programs can interact with the outside world.
1) When you include a file and then compile your work do you create another file which can be avoided if you don't use includes but rather just put the file's contents into your code?
Even if the preprocessor did create another file, it would only be temporary until the source file is compiled. However, this doesn't usually happen, as far as I know.
A note in the standard states:
Source files, translation units and translated translation units need not necessarily be stored as files, nor need there be any one-to-one correspondence between these entities and any external representation. The description is conceptual only, and does not specify any particular implementation.
-- 2.1 Phases of translation, ISO/IEC 14882:2003
pcbrainbuster
05-15-2007, 07:55 PM
cin is an input stream: an instance of the std::istream class.
I am lost at classes (don't know what they are... please help :))
Care to prove it? The only reason why I ask is that lots of people get it wrong. For instance, consider the code below:
Code:
#include <iostream>
int main() {
long value = 0x7FFFFFFF;
std::cout << ++value;
return 0;
}
I never understood what ++[variable] was even in javascript, am not up to that yet, is it needed? And isn't using hex, octal useless in this situation?
Additional classes and functions should be created as need dictates. If a console-based program suggests the use of an abstract data type, then design a class. If an algorithm can be decomposed into many distinct parts, create functions for each of them. The fact that you're using the console has no effect on the process of programming, only how programs can interact with the outside world.
You lost me in the vocabulary, but anyway I don't yet know how to create a function/class or connect to fnction/class or know how to use cin.get() to capture text written and use it...
Actually one sec I have a C++ console programming book and whn I finish it then should ask the questions but while then here is one big one -
1) Everytime I mension I want to build/learn GUI programming, I always get asked what type of GUI, at this point I have no idea on what you are trying to say so just please answer this question for now...
mwinter
05-15-2007, 08:22 PM
I am lost at classes (don't know what they are... please help :))
You know what an object (in the context of OO programming) is, right?
I never understood what ++[variable] was even in javascript,
It's similar to x++, however the two expressions evaluate to different values:
#include <iostream>
int main() {
int post = 0,
pre = 0,
temp;
std::cout << post << ' ';
temp = post++;
std::cout << temp << ' ' << post << std::endl;
std::cout << pre << ' ';
temp = ++pre;
std::cout << temp << ' ' << pre;
return 0;
}
The output from this will be:
  0 0 1
  0 1 1
Notice how the second value, that of temp, changes. The expression with the post-increment operator evaluates to the value of the variable before incrementation. That is, incrementation occurs post (after) obtaining the expression result value. The pre-increment operator increases the value of the variable, and this incremented value is used as the expression result.
am not up to that yet, is it needed?
Many features in programming languages aren't needed, but they do make things easier in certain cases.
And isn't using hex, octal useless in this situation?
Useless? No, but it's not essential, either. However, the specific number (expressed in hexadecimal) is significant and 0x7FFFFFFF is more recognisable than 2147483647.
Additional classes and functions should be created as need dictates. If a console-based program suggests the use of an abstract data type, then design a class. If an algorithm can be decomposed into many distinct parts, create functions for each of them. The fact that you're using the console has no effect on the process of programming, only how programs can interact with the outside world.
You lost me in the vocabulary,
Time to get out the dictionary, then, but the gist is: using console or graphical interfaces doesn't affect how you go about writing code. If many user-defined functions are necessary or make things easier, use them regardless of the interface.
1) Everytime I mension I want to build/learn GUI programming, I always get asked what type of GUI, at this point I have no idea on what you are trying to say so just please answer this question for now...
I haven't asked what type, but what you want to use to implement it. Different toolkits provide different features, affecting how you may go about many other tasks, the interface itself notwithstanding.
1) Everytime I mension I want to build/learn GUI programming, I always get asked what type of GUI, at this point I have no idea on what you are trying to say so just please answer this question for now...
Well, the main question is on what operating system do you want your application to run?
A smart and easy choice would be to use a toolkit, such as wxWidgets (http://www.wxwidgets.org/) or Qt (http://www.trolltech.com/products/qt), which can be easily ported to many different platforms.
However the point is that you must first understand the language and know how to use it (e.g. stack, heap, pointers, class derivation etc etc...).
pcbrainbuster
05-15-2007, 08:48 PM
#include <iostream>
int main() {
int post = 0,
pre = 0,
temp;
std::cout << post << ' ';
temp = post++;
std::cout << temp << ' ' << post << std::endl;
std::cout << pre << ' ';
temp = ++pre;
std::cout << temp << ' ' << pre;
return 0;
}The output from this will be:
0 0 1
0 1 1
I just don't get it ! When you gave temp the value post++ it should have given temp post's value plus one... But it didn't :( I am sorry man but your going to have to use more explanation, sorry.
Time to get out the dictionary, then, but the gist is: using console or graphical interfaces doesn't affect how you go about writing code. If many user-defined functions are necessary or make things easier, use them regardless of the interface.
I know but GUI programs seem WAY more impressive :)
I haven't asked what type, but what you want to use to implement it. Different toolkits provide different features, affecting how you may go about many other tasks, the interface itself notwithstanding.
Do you mean my compiler by toolkit? And wht do you mean by implementation?
mwinter
05-15-2007, 08:50 PM
However the point is that you must first understand the language and know how to use it (e.g. stack, heap, pointers, class derivation etc etc...).
The stack is an implementation detail and not part of the language. :)
I just don't get it ! When you gave temp the value post++ it should have given temp post's value plus one...
No, it shouldn't. That's how the two operators differ. Whilst both increment the value of a variable, they evaluate differently. As you saw, post-increment (x++) yields the value then increments the variable, whereas pre-increment (++x) increments the variable then yields that new value. The point when the incrementation occurs changes: with post-increment it comes after determining the value to yield, whereas with pre-increment it comes before the determining the value.
Do you mean my compiler by toolkit?
No. I'm referring to the library (and tools that go with it) that you'd use to create graphical user interfaces.
And wht do you mean by implementation?
Hmm. I'm finding it awkward to describe. An implementation is the performance, if you will, of some set of instructions. So, a block of code will be an implementation of an algorithm.
The stack is an implementation detail and not part of the language. :)
Yeah, I know :p I was just thinking of all that pointers stuff.
pcbrainbuster
05-15-2007, 09:05 PM
Well ey mwinter, you should have also answered that toolki question :p
mwinter
05-15-2007, 09:11 PM
Well ey mwinter, you should have also answered that toolki question :p
I did. Check again. :)
pcbrainbuster
05-15-2007, 09:38 PM
Lol :), anyway I did a test to see what would happen and here it is -
#include <iostream>
using namespace std;
int main() {
int num1 = 1;
int num2 = 1;
int res1 = ++num1;
int res2 = num2++;
cout << res1 << endl << res2;
cin.get();
}
And the result -
2
1
The second alue did not go up ?!? :confused:
I now understand simple [var]++ but not ++[var]...
edit-Also, when you create a global directive (i think its called eg using namspace std;) do you automatically make every object it supports a keywoard?
mburt
05-15-2007, 09:49 PM
Actually, in that case, the int res1 went up (++num1), and res2 (num2++) didn't.
mwinter
05-15-2007, 09:51 PM
#include <iostream>
using namespace std;
int main() {
int num1 = 1;
int num2 = 1;
int res1 = ++num1;
int res2 = num2++;
cout << res1 << endl << res2;
cin.get();
}
And the result -
2
1
The second alue did not go up ?!? :confused:
It did. There's a distinction between the expression, x++, and the variable, x, itself.
int res2 = num2++;
is the same as:
int res2 = num2;
num2 = num2 + 1;
However,
int res1 = ++num1;
is like:
num1 = num1 + 1;
int res1 = num1;
Compare the two closely and pay attention to the difference in order, to when the addition occurs!
pcbrainbuster
05-15-2007, 09:58 PM
OK I see I will peorm some tests in the morni and work it out, goodnight :) and thanks.
pcbrainbuster
05-16-2007, 04:10 PM
Well anyway I think I will focus on small issues later... Anyway here is a sample console program by your's truly -
#include <iostream>
using namespace std;
int main()
{
int var1;
cout << "Another successful program by Matahir Shah!" << endl << endl;
cout << "What's your age\?: ";
cin >> var1;
cin.ignore();
if (var1==13) {
cout << "Cool, you have the same age as me!";
cout << endl << endl;
cout << "Goodbye :)";
cin.get();}
else if (var1<=12) {
cout << "Your a kid\?";
cout << endl << endl;
cout << "Goodbye :)";
cin.get();}
else {
cout << "Your pretty much past my age...";
cout << endl << endl;
cout << "Goodbye :)";
cin.get();}
}
I need a proffessional opinion, am I learning fast or slow (this is around my third day of console C++)...
edit-Crud, I just realized something, the smilies are :)...
mwinter
05-16-2007, 05:39 PM
using namespace std;
I would still recommend against including that declaration, just as a Java developer would probably recommend against
import java.net.*;
Blindly introducing names into the global namespace can lead to clashes and can reduce the clarity of code because it's not always obvious where a variable or type originated. The "std::" qualifier isn't exactly troubling. :)
cout << "What's your age\?: ";
Any particular reason why you're escaping that question mark?
cin >> var1;
Just as in any other situation, you really should validate input (though I realise this is just a trivial example).
I need a proffessional opinion, am I learning fast or slow (this is around my third day of console C++)...
I don't know. It depends what you understand. You still didn't answer my earlier test (which, I suppose, is open to anyone that wants a crack at it as it will still generate discussion). I don't know whether you've grasped classes (which are a huge part of C++), overloading, member accessibility, inheritance (including virtual inheritance), pointers, references, copy and default constructors, destructors, sequence points, the heap, exceptions, run-time type information, casting (including up- and down-casting objects), and probably a ton of other things that don't immediately come to mind.
pcbrainbuster
05-16-2007, 09:58 PM
I would still recommend against including that declaration, just as a Java developer would probably recommend against
Code:
import java.net.*;
I agee but this ws just a example tht did not include any other variable or so that may intefer/caue problems with the program, so I just thought it was more practical inthis case...
Any particular reason why you're escaping that question mark?
I didn't know until now :)...
Just as in any other situation, you really should validate input (though I realise this is just a trivial example).
Validate input?
And also I don't really know anything in that list of ours as havn't gotten there yet...
mwinter
05-16-2007, 10:36 PM
Any particular reason why you're escaping that question mark?
I didn't know until now :)...
The only characters that need escaping in character and string literals is the single quote (') in character literals ('\''), the double quote in string literals ("\""), the backslash if you want a literal backslash ('\\' or "\\") in either literal, and new-line characters (carriage return, \r; line feed, \n). All other characters can be represented as-is, though there are the other usual escape sequences: vertical tab (\v); backspace (\b); form feed (\f); alert (\a); octal escapes (\ooo); hexadecimal escapes (\xhhh).
Just as in any other situation, you really should validate input (though I realise this is just a trivial example).
Validate input?
You're expecting an age, so you should check that you were given a sensible value. For instance:
Is it a number?
Is that number positive (greater than zero)?
Is that positive number greater than some sensible minimum (you probably don't expect a five-year-old to be answering)?
Is that positive number less than some sensible maximum age (the oldest person ever died at an age of 122 years old)?
pcbrainbuster
05-17-2007, 06:57 AM
It wasonly a small test but out of that list ther is one thing I just realized haunts me, how do you check if anything is a number or character...
mwinter
05-17-2007, 05:00 PM
It wasonly a small test
I did acknowledge that. :)
but out of that list ther is one thing I just realized haunts me, how do you check if anything is a number or character...
There are different ways, depending on context. In your case, part of it is done for you as the formatted arithmetic extractor [operator>>(int& value), and similar] will only consume numeric characters. However, you don't check that the extraction is successful, or that the number is sensible.
#include <iostream>
int main() {
const unsigned int myAge = 13;
unsigned int age = 0;
// Until an acceptable number is obtained, repeat the prompt
while ((std::cout << "What's your age? ") && !(std::cin >> age) || (age < 5) || (age > 150)) {
std::cout << "Please enter a number between 5 and 150; ";
// Clear the error state
std::cin.clear();
// Remove any remaining characters from the input stream
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
if (age == myAge) {
std::cout << "Cool! You're the same age as me.";
} else if (age < myAge) {
std::cout << "You're a kid?!";
} else {
std::cout << "Wow, you're past it!";
}
// Output salutation on a new line and flush the output buffer
std::cout << '\n' << "Goodbye." << std::endl;
// Removing remaining input characters and pause for convenience
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cin.get();
return 0;
}
Note the difference in the use of the std::istream.ignore method. If the method is called, as you did, without any arguments, it uses the defaults which only extracts one character.
pcbrainbuster
05-17-2007, 07:51 PM
#include <iostream>
int main() {
const unsigned int myAge = 13;
unsigned int age = 0;
// Until an acceptable number is obtained, repeat the prompt
while ((std::cout << "What's your age? ") && !(std::cin >> age) || (age < 5) || (age > 150)) {
std::cout << "Please enter a number between 5 and 150; ";
// Clear the error state
std::cin.clear();
// Remove any remaining characters from the input stream
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
if (age == myAge) {
std::cout << "Cool! You're the same age as me.";
} else if (age < myAge) {
std::cout << "You're a kid?!";
} else {
std::cout << "Wow, you're past it!";
}
// Output salutation on a new line and flush the output buffer
std::cout << '\n' << "Goodbye." << std::endl;
// Removing remaining input characters and pause for convenience
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cin.get();
return 0;
}
I am not up to those methods... Please explain each one with great detail (don't worry it shouldn't take long :))...
And obviously some questions -
1) Can you please explain the methods to me as I understand everything else?
2) Can the if, else if, else statements work same as JavaScript (eg the parenthesis for the statement (what I mean is that you used an extra set of parenthesis for each of your conditions, though I understand that the same idea was used for JavaScript I am just wondering))
3) This is completely your choice but can you please explain classes to me using primitive vocabulary :)
Thanks.
P.S. - How are you at C++, mburt? And mwinter? How advanced I mean?
mburt
05-17-2007, 08:02 PM
Not everything is a "method". That is simply a while loop initiating the std calls, and verifying the input (age) as either more than 5 or less then 150. Then the rest is just calling the if statements, eg. if you are the same age as me (do something here).
Very simple.
P.S. - How are you at C++, mburt? And mwinter? How advanced I mean?
There's not much to console scripting like that... I'm starting to work with wxWidgets (a C++ application) to make creating Windows/Linux programs easier. It makes coding alot easier as well, but still not "easy".
pcbrainbuster
05-17-2007, 08:07 PM
Not everything is a "method". That is simply a while loop initiating the std calls, and verifying the input (age) as either more than 5 or less then 150. Then the rest is just calling the if statements, eg. if you are the same age as me (do something here).
Very simple.
Ever thought that I wasn't talking about everything :)? I am actually talking about the ignore(arguments) and the clear method (loops are easy...)...
And you also seem to have mensioned that you are a wxWidget programmer right? Please tell me all the types and differences if you have time :).
Thanks.
mburt
05-17-2007, 08:19 PM
Please tell me all the types and differences if you have time .
(Mouth gaping :))
www.wxWidgets.org
pcbrainbuster
05-17-2007, 08:27 PM
Well I checked it and still don't see the difference compared to any other type... This is so anoyying as there is a million types and each have a different coding system if you know what I mean...
I really need a site which gives all the differences...
All the main types (int, double, bool ...) still remain, you just get another ~560 classes and a bunch of enums (which are also "types").
pcbrainbuster
05-17-2007, 08:29 PM
HUH, who are you posting to?
HUH, who are you posting to?
To you.
I'm just saying that wxWidgets isn't a "different thing". It's all the same C++ where someone has just made classes to simplify creation of applications, but to use them you have to understand the "usage" of the language (I don't mean that you must know all the cin's methods etc, but simply how variables are created, used, destroyed, functions/classes declared an so on..).
pcbrainbuster
05-17-2007, 08:43 PM
Out of that small (uncompleted) list I understand all but how to destroy variables and create classes, might as well quickly tell me how to 'kill' variables as it possibly takes only one line of code :)...
questions :
1) And what is a native program?
2) I guess I am stll lost with some of this stuff, is there only really two type of programs you can create while the rest are components/controls? (eg win32 and console programs and AciveX Control, dlls, etc components)...
mwinter
05-17-2007, 10:20 PM
I am not up to those methods... Please explain each one with great detail (don't worry it shouldn't take long :))...
If the arithmetic extractor cannot convert the characters in the input stream into the required numeric type (an unsigned integer, in my example) then the fail bit of the stream state is set to indicate the error. To make sure that the next loop iteration doesn't detect a prior error, the stream state needs to be reset, and this is the purpose of the std::istream.clear method: to reset the error state.
Even if the characters in the input stream can be converted to a number, there may have been trailing characters that could not. For instance, entering "20f" would result in the number 20, and "f" would remain in the input stream. This character is no longer needed so the std::istream.ignore method is used. The first argument to this method determines the maximum number of characters to remove from the stream, defaulting to one (1). The code that you see in that argument position
std::numeric_limits<std::streamsize>::max()
obtains the largest possible number. The std::numeric_limits class has a number of specialised templates that have data about the properties of certain types, including all fundamental types. The type, std::streamsize, is a typedef (think alias) that corresponds to one of the signed fundamental types (short, int, long), therefore the properties of it will be known. Clearly, the static method, max, returns the maximum value of the indicated type.
The second argument to the std::istream.ignore method is the delimiter character, and defaults to the end-of-file condition. If this character is encountered whilst scanning the input stream, the process of disposing of characters stops. In the example, the user presses the Return key to submit a value, therefore we ignore as many remaining characters as possible, stopping when we find the Return.
2) Can the if, else if, else statements work same as JavaScript (eg the parenthesis for the statement (what I mean is that you used an extra set of parenthesis for each of your conditions, though I understand that the same idea was used for JavaScript I am just wondering))
It's not necessary to use as many parentheses as I did, but I prefer to group subexpressions explicitly, rather than relying on operator precedence. I've used a lot of languages, and I've simply given up trying to remember the small differences between them.
3) This is completely your choice but can you please explain classes to me using primitive vocabulary :)
I would have done so long ago, but you didn't tell me if you understood what objects are. You should from scripting, but it would be a waste of effort to approach classes from the point of view of objects if you didn't understand the latter.
P.S. - How are you at C++, mburt? And mwinter? How advanced I mean?
I'm a bit rusty, as my first foray into this thread will attest, but I'm quite competent.
Out of that small (uncompleted) list I understand all but how to destroy variables and create classes, might as well quickly tell me how to 'kill' variables as it possibly takes only one line of code :)...
C++ has block scoping rules, unlike ECMAScript and its derivatives. That is,
int main() {
int i = 0;
{
int j = 1;
/* Here, i=0 and j=1 */
}
/* Here, i=0 and j doesn't exist! */
}
As soon as a variable falls out of scope, it ceases to exist. This is no different from scripting, but now there are more ways to introduce new levels of scope. For instance, even for statements introduce scope:
int main() {
for (int i = 0; i < 10; ++i) {/* i will increase from 0 to 9 */}
/* i does not exist here */
}
Deleting items from the heap - an area of memory used to hold data created at run-time - will destroy them. This doesn't necessarily mean that the values will be eradicated, just as it doesn't above, but it does mean that the memory used by them can be used by something else - trying to read from a region of released memory can lead to big trouble.
Finally, objects have destructors and destructors can be called explicitly, running the code to tear down that object. It's not the done thing, though - in fact, it should be avoided entirely. Destructors will be called automatically when the object goes out of scope, or is deleted from the heap.
1) And what is a native program?
A native program uses instructions that the processor can run directly. Compare to Java, for example, which usually requires some intermediary to convert from Java bytecode to native instructions.
2) I guess I am stll lost with some of this stuff, is there only really two type of programs you can create while the rest are components/controls? (eg win32 and console programs and AciveX Control, dlls, etc components)...
In general, there are applications and libraries. Applications can be console-based, graphically-based, or even have no interface at all. Libraries can be static (the code is included directly in the application) or dynamic (the code is in a separate file that can be shared by many applications).
pcbrainbuster
05-18-2007, 03:05 PM
Hmmm.... I have an question obviously -
I found this site which offers win32 GUI tutorial and as you know I really want to learn this now, I may find somethings which I do not understand like pointers (which I learnt is 'memory control' sort of) which I can easly search up on the Internet...
Do you think I should go for it as I really want to?
mwinter
05-18-2007, 03:13 PM
I found this site which offers win32 GUI tutorial and as you know I really want to learn this now, I may find somethings which I do not understand like pointers (which I learnt is 'memory control' sort of) which I can easly search up on the Internet...
Do you think I should go for it as I really want to?
No. You need to accept that learning a programming language as complicated as C++ takes time, and rushing ahead may only lead to trouble. You aren't in a safe little bubble like you are within a browser. I also wouldn't really recommend that you start with the Win32 API. Not only is it quite complicated, but it's written with C (not C++) interfaces and you should concentrate only on C++ at the moment. Qt provides a C++ API, as does wxWidgets.
I vividly remember crashing my computer through mistakes, and I knew more about C++ then than you do now.
pcbrainbuster
05-18-2007, 03:38 PM
Ok, but why is it like that, you know, that mix of C and C++?
And also do you mind becoming my tutor as I think having a teacher is easier to work with then a site. And if you don't mind classes is something I really think I should start learning..
And thanks for being mean and direct by that No :), also please use VERY BASIC !!! Vocabulary as most of the time I get lost on the first sentence because of it :p...
Soooooo, what do you say?
mwinter
05-18-2007, 05:35 PM
Ok, but why is it like that, you know, that mix of C and C++?
It's not a mix, it's purely C. The reason is that, certainly when Windows was young, C was still very popular for application development. If the API was written with C++, no C developer could use it; whilst C is more-or-less compatible with C++, the reverse is not true.
Microsoft did introduce MFC, the Microsoft Foundation Class library, which is a C++ wrapper for many parts of the Win32 API but it does still require "raw" communication with the parts that weren't covered. However, I've never considered MFC to be that friendly.
And also do you mind becoming my tutor as I think having a teacher is easier to work with then a site. And if you don't mind classes is something I really think I should start learning..
It depends how much of my time you'll require. I've no problem with helping you learn, but I do like to have a life (sometimes :)) when I get home. That does mean that you'll need to do some self-directed learning, as well as trying to research answers for yourself (at the C++ FAQ [Lite] (http://www.parashift.com/c++-faq-lite/), for example). You can double-check here, or even on the comp.lang.c++ newsgroup. The other reason for learning with a book is that you'll usually have exercises of some kind to work through, which I strongly recommend you do.
Another strong recommendation is that you look for information regarding object-oriented design, and that you get into the habit of designing software before starting to implement it. Even the relatively trivial stuff. I didn't when I taught myself, and it's left me extremely poor at design.
And thanks for being mean and direct by that No :)
I was just trying to be honest.
also please use VERY BASIC !!! Vocabulary as most of the time I get lost on the first sentence because of it :p...
I'll try, but I can be more precise with formal language, which is why I prefer to use it.
Soooooo, what do you say?
I cautious yes, though I reserve the right to withdraw later on if necessary. Tonight isn't a good time to start, though. This is one of those evenings where I want a life. :D
pcbrainbuster
05-18-2007, 06:22 PM
It's not a mix, it's purely C. The reason is that, certainly when Windows was young, C was still very popular for application development. If the API was written with C++, no C developer could use it; whilst C is more-or-less compatible with C++, the reverse is not true.
Microsoft did introduce MFC, the Microsoft Foundation Class library, which is a C++ wrapper for many parts of the Win32 API but it does still require "raw" communication with the parts that weren't covered. However, I've never considered MFC to be that friendly.
What do they plan to od about this?
It depends how much of my time you'll require. I've no problem with helping you learn, but I do like to have a life (sometimes ) when I get home. That does mean that you'll need to do some self-directed learning, as well as trying to research answers for yourself (at the C++ FAQ [Lite], for example). You can double-check here, or even on the comp.lang.c++ newsgroup. The other reason for learning with a book is that you'll usually have exercises of some kind to work through, which I strongly recommend you do.
Another strong recommendation is that you look for information regarding object-oriented design, and that you get into the habit of designing software before starting to implement it. Even the relatively trivial stuff. I didn't when I taught myself, and it's left me extremely poor at design.
Of course I have experience with OOP what do you think JavaScript was all about :). Ialready have the habit of creating programs and what not (I have created many console based programs and HTML, CSS (imp), JavaScript, some PHP, though these don't count they are still programming in it's own way).
I'll try, but I can be more precise with formal language, which is why I prefer to use it.
Thanks :)...
I cautious yes, though I reserve the right to withdraw later on if necessary. Tonight isn't a good time to start, though. This is one of those evenings where I want a life.
Go down to Allen street I heard there taking people's lives there! (LOL do you get it :p)... Anyway good for you, whats your job?
edit- Some questions -
1) What is ment by "at runtime"?
2) How many things are there that I have to learn the bases of (eg pointers, classes etc, these count as two of those)?
3) Whats is win32 GUI or win32 API difference?
4) How long do you think it will take me to learn console programming?
Ok, but why is it like that, you know, that mix of C and C++?Windows is written primarily in C. C++ can call routines written in C, of course, but since C has no object support it can't take advantage of C++'s object-orientation (e.g. to return an object from a routine or accept one as an argument). Instead, it uses COM, a very ugly language-independent object format. COM is most definitely not for beginners (and really shouldn't have to be considered at all, IMO: it's high time the Win32 API was brought up to date with C++ and objects).
please use VERY BASIC !!! Vocabulary as most of the time I get lost on the first sentence because of itAre you a native English speaker? Either way, a dictionary should solve your problems (and simultaneously augment your lexicon).
pcbrainbuster
05-18-2007, 07:33 PM
Well I live in England but don't know what native means yet or lexicon or augment, I really hate lookng up words which is why I never do it...
And why havn't they used C++ to make Windows, I mean it isn't such a big step from C to C++ now is it, also is Vista primarily C or C++?
And if Windows in primarily C then why is the win32 API configurations working when your scripting with C++?
boxxertrumps
05-18-2007, 08:07 PM
You should always look to increase your vocabulary, that way you can hold up a conversation in a more fluent manner and give a more sophisticated impression.
native means from birth, native country = place you've lived most of your life, native language is the one that you have spoken for most of your life. I beleive a lexicon is something that tells how fluently you can speak/comprehend a language(or something to that affect.)
It is a big step from C to C++... twey, Windows doesn't release the source code, and what they tell you can be a lie because you have no way of checking.
But for Linux, i believe the kernel is made up of c++ and python.
pcbrainbuster
05-18-2007, 08:16 PM
To tell the truth, if I made any program I really won't be willing to give the source code to ANYONE except for mburt, Twey and especially mwinter as I owe him alot...
And for your information, I understoofd everything you said :)...
boxxertrumps
05-18-2007, 08:24 PM
Whats the point of hiding source code?
And why havn't they used C++ to make Windows, I mean it isn't such a big step from C to C++ now is it, also is Vista primarily C or C++?Yes, it's a huge step switching an application between paradigms. It involves a complete redesign, and it would most likely have to be rebuilt from the ground up. Nevertheless, I think Windows is long overdue. I think Vista is still primarily C and COM, yes, but I would suspect that they will move to .NET (probably C#) for most user-mode components.
And if Windows in primarily C then why is the win32 API configurations working when your scripting with C++?A routine, when compiled, can be used by any language that supports the same calling convention.
twey, Windows doesn't release the source code, and what they tell you can be a lie because you have no way of checking.Part of the Win2K source code was leaked, and some things can be determined from looking at the compiled product. Also, they have no reason to lie in this case.
But for Linux, i believe the kernel is made up of c++ and python.What? Nobody's stupid enough to write part of a kernel in an interpreted language. The Linux kernel is written entirely in C and assembly language (specifically gas), as far as I'm aware, for performance reasons. The Windows kernel, too, will remain in C. I'm talking about the user-mode components.
To tell the truth, if I made any program I really won't be willing to give the source code to ANYONE except for mburt, Twey and especially mwinter as I owe him alot... Why?
boxxertrumps
05-18-2007, 08:38 PM
Nobody's stupid enough to write part of a kernel in an interpreted language.
I thought that you could compile python?
pcbrainbuster
05-18-2007, 08:43 PM
Yes, it's a huge step switching an application between paradigms. It involves a complete redesign, and it would most likely have to be rebuilt from the ground up. Nevertheless, I think Windows is long overdue. I think Vista is still primarily C and COM, yes, but I would suspect that they will move to .NET (probably C#) for most user-mode components.
Is C# a better version of C++?
A routine, when compiled, can be used by any language that supports the same calling convention.
Lost you here...
What? Nobody's stupid enough to write part of a kernel in an interpreted language. The Linux kernel is written entirely in C and assembly language (specifically gas), as far as I'm aware, for performance reasons. The Windows kernel, too, will remain in C. I'm talking about the user-mode components.
Harsh... And I am gueesing that Python is the interpreted language here?
Why?
Well because, I wouldn't really want anyone else to have a look at my work, but I really do owe mwinter as he as helped me so much with C++ while you and mburt have helped me alot with my web scripting which is only why I will be comfortable with sharing it with you lot...
I thought that you could compile python?To a bytecode, yes. There's no native interpreter at the moment, and it would probably be considerably less efficient than C if there were -- Python's features don't translate well to a machine level.
Is C# a better version of C++?No. C# is a language that runs on the .NET platform, allegedly loosely based on C++, although in my opinion it's just Microsoft's rather poor clone of Java (although Java does rather resemble C++ too, so I guess it could just be coincidence).
Lost you here...I'm not surprised, it wasn't for your benefit. Basically, when you have a function like:
int somefunc(int arg1, int arg2) {
// some code
}
// ...
somefunc(1, 2);in C, it gets translated to something like:
somefunc:
; some code
mov returnvalue, %eax
ret
push 2
push 1
jmp somefuncin machine code (above in what's probably some horrible hybrid assembly language that's all I remember of gas, obviously). That's (again, if I remember correctly) the cdecl convention, which is default for C and global functions in C++ programs. However, some languages do things differently: they might, for example, push the arguments in the opposite order, or store the return value somewhere else. In this case, the language cannot interoperate with compiled code generated from one with a different calling convention unless either language is able to tell its compiler about these differences somehow and have it compensate.
Harsh... And I am gueesing that Python is the interpreted language here?Yes. Why is it harsh? It's true, you'd have to be some kind of idiot to write a kernel in an interpreted language (or not care if your machine ran like treacle, or perhaps have an incredibly powerful machine).
I wouldn't really want anyone else to have a look at my workWhy?
pcbrainbuster
05-18-2007, 09:31 PM
To a bytecode, yes. There's no native interpreter at the moment, and it would probably be considerably less efficient than C if there were -- Python's features don't translate well to a machine level.
By bytecode do you mean binary (0 and 1)? And macine level is binary right?
No. C# is a language that runs on the .NET platform, allegedly loosely based on C++, although in my opinion it's just Microsoft's rather poor clone of Java (although Java does rather resemble C++ too, so I guess it could just be coincidence).
What exactly is a .Net platform? Whatd do you mean by resemble C++?
...in machine code (above in what's probably some horrible hybrid assembly language that's all I remember of gas, obviously). That's (again, if I remember correctly) the cdecl convention, which is default for C and global functions in C++ programs. However, some languages do things differently: they might, for example, push the arguments in the opposite order, or store the return value somewhere else. In this case, the language cannot interoperate with compiled code generated from one with a different calling convention unless either language is able to tell its compiler about these differences somehow and have it compensate.
Global function? Can you make local functions? If you can then is it as simple as defining a function in a function like javascript or is there another concept?
Why?
Here's an example, say you created such a great program that could so many things like video recording (of the users current screen), picture taking of windows, icon creating etc and you had written you name in the credits section, then outof no where this guy comes along and downloads your source and then inputs his name instead of your's, then he takes all the credit for it and makes it go shareware!!! Wouldn't this just make you angry?
boxxertrumps
05-18-2007, 09:36 PM
then outof no where this guy comes along and downloads your source and then inputs his name instead of your's, then he takes all the credit for it and makes it go shareware!!! uhh... Creative commons, GPL, Copyright/left etc?
People cant outright steal your work if you do this...
Also, if noone can see your work, they cant help with problems or point out potential flaws...
The best thing about open source projects is that effectively every programmer in the community can work on it, to make it better. This is why linux is better than windows...
MS decides what is good in the code, and the end users have no say. for linux, the end users decide everything about the code(fix flaws/bugs, up the efficiency of the code, etc...), and it does exactly what they want it too.
pcbrainbuster
05-18-2007, 09:49 PM
uhh... Creative commons, GPL, Copyright/left etc?
People cant outright steal your work if you do this...
Since when does really anyone care about this, they usually just remove that 'notice' and get on with it...
The best thing about open source projects is that effectively every programmer in the community can work on it, to make it better. This is why linux is better than windows...
MS decides what is good in the code, and the end users have no say. for linux, the end users decide everything about the code(fix flaws/bugs, up the efficiency of the code, etc...), and it does exactly what they want it too.
They ca eighther makeit better or just steal it... End users do have say - there is a sort of forum on there site where you can suggest ideas also you can email them... Windows also sends error reports to micrsoft which is how they fix bugs and improve efficiency...
Since when does really anyone care about this, they usually just remove that 'notice' and get on with it...If it's causing you trouble, sue them. Better still, if it's under the GPL, contact the FSF, and they'll sue them for you. If it's not causing you trouble, what's the problem?
By bytecode do you mean binary (0 and 1)? And macine level is binary right?Binary is a numerical base. The actual data represented by those numbers varies. We loosely use the term "binary" to mean any data that can't be read with a text editor, but of course text data is binary too. Python bytecode is a binary format in that sense, but it is not a machine-readable format: it requires another layer to run.
Windows also sends error reports to micrsoft which is how they fix bugs and improve efficiency...Hahahahahahahahaha.
What exactly is a .Net platform?Wikipedia is your friend (http://en.wikipedia.org/wiki/Microsoft_.NET).
Global function? Can you make local functions? If you can then is it as simple as defining a function in a function like javascript or is there another concept?No, but one can make functions within a class or namespace.
pcbrainbuster
05-18-2007, 10:44 PM
If it's causing you trouble, sue them. Better still, if it's under the GPL, contact the FSF, and they'll sue them for you. If it's not causing you trouble, what's the problem?
You simply kept asking why so I had to answer in one way or another :)...
Hahahahahahahahaha.
I guess I am a joker, what's so funny :confused:...
You simply kept asking why so I had to answer in one way or another :)...Er, so there isn't a reason, you just felt like you had to make one up rather than admitting that? :-\
I guess I am a joker, what's so funny :confused:...Microsoft are notorious for not listening to user feedback.
boxxertrumps
05-19-2007, 03:27 AM
Microsoft are notorious for not listening to user feedback.
This is seconded.
PC brainbuster, the examples i gave are legally binding, it doesn't matter if the notice is intact with the document or not.
djr33
05-19-2007, 10:29 AM
If they do anything with the feedback, it's analyze for a better profit for who to sell to, or check for verification of genuine software.
Nothing to do with actually caring about if you like it. Just how much money you spent.
pcbrainbuster
05-19-2007, 10:51 AM
Er, so there isn't a reason, you just felt like you had to make one up rather than admitting that? :-\
The thing is ifyou leave your source code open to everone, then one guy will come along just remove the legal thing and just get on with it... I was just trying to suggest what people do with open sources, they just don't listen to what you say...
Some more question -
1) Mind explaining classes to me Twey? Your vocab is a little less advanced compared to mwinter :)...
2) You said something about if the routin is the same it doesn't matter what language you are using, so what is a routine?
3) What is the difference between win32 GUI and win32 API?
4) How complicated is C++ in general?
boxxertrumps
05-19-2007, 04:26 PM
one guy will come along just remove the legal thing and just get on with it
Thats illegal, they can get sued for that.
It doesn't matter wether or not the notice is attached to the thing.
mwinter
05-19-2007, 06:26 PM
Of course I have experience with OOP what do you think JavaScript was all about :).
Using an object-oriented (or object-based) language isn't the same as understanding the paradigm (model) itself and designing code that follows its principles. For instance, what can you tell me about encapsulation, inheritance, polymorphism, and abstraction? If you understand the OOP, you should know all of them.
I already have the habit of creating programs and what not ...
But did you design them? Did you sit down and plan out a specification? Did you isolate candidate classes, data and operations? Did you design test cases, performing unit, integration, and system tests?
1) What is ment by "at runtime"?
As the program runs.
For example, when a variable is declared in a function or as a global, that memory is set aside (allocated) when the program is created (at design-time). However, sometimes you can't be certain how much memory you'll need. One solution is to allocate lots of memory so that you'll always have enough, but if it's not actually needed, it's a waste. The alternative is to grab new regions of memory while the program runs (at run-time), as and when it's needed.
2) How many things are there that I have to learn the bases of (eg pointers, classes etc, these count as two of those)?
The concepts of OOP (which I listed earlier) and how they apply to C++ - a huge portion of the language; pointers; references; exceptions; casting; memory allocation and deallocation; templates; and, the main features of the Standard Template Library (STL).
3) Whats is win32 GUI or win32 API difference?
The Win32 API (Application Programming Interface) is the functions built into Windows that programs use to perform all sorts of tasks, from reading and writing files to creating windows, from creating threads to drawing, from accessing network devices to playing audio. I don't think that anyone has mentioned the phrase "Win32 GUI", but if they did, they would mean creating a graphical user interface with the Win32 API.
4) How long do you think it will take me to learn console programming?
There's not much to learn about the console. The only reason why I would recommend sticking to it for now is that it's a simple way to observe results. Your aim now is to learn the language, as well as general programming techniques. I don't remember how long it took me, but I'd get at least a few months for the basics of the language (perhaps less depending on past experience), to a couple of years to master it (again, depending upon experience); roughly the same as most languages.
somefunc:
; some code
mov returnvalue, %eax
ret
push 2
push 1
jmp somefunc
Unless gas is very different from the assembly languages I've used, you'd want to call somefunc, otherwise the return address won't be added to the stack. Something (caller or callee) also needs to be responsible for removing the arguments from the stack.
By bytecode do you mean binary (0 and 1)?
No. Bytecode is a middle language, if you will; something that exists between source code and instructions that the processor can execute directly. The name is bytecode because originally bytecode languages used a single byte to represent instructions. Bytecode requires translation: conversion into machine code.
And macine level is binary right?
Machine code is the data that processors can execute directly.
Whatd do you mean by resemble C++?
It looks like C++ (but it isn't).
1) Mind explaining classes to me Twey? Your vocab is a little less advanced compared to mwinter :)...
That's a back-handed compliment.
I'm a little disappointed that no-one addressed the exercise I posted earlier this week:
#include <iostream>
int main() {
long value = 0x7FFFFFFF;
std::cout << ++value;
return 0;
}
Without running this, tell me what value is written to the output stream, cout. This is a good, basic exercise for anyone using C++ (or C, for that matter).
The answer that I was expecting to receive was -2147483648, however that would be incorrect: the behaviour is either implementation-specific or undefined.
Fundamental data types in both C and C++ guarantee minimum limits. That is, signed character types must provide for values in the range [-127,127], signed short integers and signed integers [-32767,32767] (though the latter is often much larger), and long integers [-2147483647, 2147483647]. However, there is no reason why these limits cannot be higher on other platforms, and this is indeed what happens. As a result, incrementing 0x7FFFFFFF may just become 0x80000000.
I mentioned that the example may also result in undefined behaviour. If the result is beyond the range supported by the data type, an exception may occur in response to the overflow. Many implementations don't do this though as numeric data is represented using a two's-complement system, making overflows reversible (hence the typical answer of -2147483648).
If the example had used an unsigned type, the behaviour would only be implementation-specific as all unsigned integers must obey modulo 2**n arithmetic (where n is the number of bits held by that type).
1) Mind explaining classes to me Twey? Your vocab is a little less advanced compared to mwinter ...You should already be fairly familiar with the concept... class-based OO is a lot easier to understand from a prototype-based OO background than vice versa. Classes act as a "template" from which objects are built, similar to a constructor function in Javascript.
2) You said something about if the routin is the same it doesn't matter what language you are using, so what is a routine?That's not what I said at all. A routine is a reusable block of code that performs a task. In C or C++, one would call it a function or method, but the term doesn't translate well to a machine level, at which one really only has a lot of jumps.
3) What is the difference between win32 GUI and win32 API?Er, a lot. Again, look up the two terms in the technical dictionary of your choice.
4) How complicated is C++ in general?How long is a piece of string?
pcbrainbuster
05-19-2007, 09:24 PM
Using an object-oriented (or object-based) language isn't the same as understanding the paradigm (model) itself and designing code that follows its principles. For instance, what can you tell me about encapsulation, inheritance, polymorphism, and abstraction? If you understand the OOP, you should know all of them.
Listening to you makes me wanna cry as I never understand anything :), what's a paradigm? And polymorphism is OOP (same thing, right?)...
But did you design them? Did you sit down and plan out a specification? Did you isolate candidate classes, data and operations? Did you design test cases, performing unit, integration, and system tests?
No, but I just thought of what I should do as I was coding and when it was finished went through it and upgraded it...
There's not much to learn about the console. The only reason why I would recommend sticking to it for now is that it's a simple way to observe results. Your aim now is to learn the language, as well as general programming techniques. I don't remember how long it took me, but I'd get at least a few months for the basics of the language (perhaps less depending on past experience), to a couple of years to master it (again, depending upon experience); roughly the same as most languages.
I plan to master console programming by half July and september at most :)...
That's a back-handed compliment.
Then thank me ...
The answer that I was expecting to receive was -2147483648, however that would be incorrect: the behaviour is either implementation-specific or undefined.
Fundamental data types in both C and C++ guarantee minimum limits. That is, signed character types must provide for values in the range [-127,127], signed short integers and signed integers [-32767,32767] (though the latter is often much larger), and long integers [-2147483647, 2147483647]. However, there is no reason why these limits cannot be higher on other platforms, and this is indeed what happens. As a result, incrementing 0x7FFFFFFF may just become 0x80000000.
I mentioned that the example may also result in undefined behaviour. If the result is beyond the range supported by the data type, an exception may occur in response to the overflow. Many implementations don't do this though as numeric data is represented using a two's-complement system, making overflows reversible (hence the typical answer of -2147483648).
If the example had used an unsigned type, the behaviour would only be implementation-specific as all unsigned integers must obey modulo 2**n arithmetic (where n is the number of bits held by that type).
Seriously what chance did I have? And I don't get ++[var] or what you just said :)...
You should already be fairly familiar with the concept... class-based OO is a lot easier to understand from a prototype-based OO background than vice versa. Classes act as a "template" from which objects are built, similar to a constructor function in Javascript.
I AM A BEGGINER AT C++ ! And what's OO?
How long is a piece of string?
What's string got to do with this?
boxxertrumps
05-20-2007, 12:28 AM
Listening to you makes me wanna cry as I never understand anything :), what's a paradigm? And polymorphism is OOP (same thing, right?)...
Dictionary or Google.
I plan to master console programming by half July and september at most :)...
Dont think you can get to a decent level of programming in less than a year, so try for summer 2008.
I AM A BEGGINER AT C++ ! And what's OO?
Again, Dictionary or Google.
What's string got to do with this?
The length of the string differs for each peice, and the complexity of C++ varies for each person that learns it.
pcbrainbuster
05-20-2007, 11:59 AM
Dictionary or Google.
JUst now I have made myself a new policy; to only look up things related to programming. Naturally I hate looking up stuff like words so this is an improvment. But right now I have to eat and look it up later :).
Dont think you can get to a decent level of programming in less than a year, so try for summer 2008.
We'll see :).
As for the rest point taken, but really the other reason I don't look up C++ related things is because the site/author doesn't explain the thing in my needed context and this can get frustrating...
mwinter
05-20-2007, 04:02 PM
Listening to you makes me wanna cry as I never understand anything
Based on what you've written in this thread, none of the words I used should be unfamiliar to you.
what's a paradigm?
So you wrote: "Of course I have experience with OOP ...", yet you don't actually know what the abbreviation means? That seems rather suspicious to me.
And polymorphism is OOP (same thing, right?)...
Not in the slightest. Polymorphism is just one concept in the object-oriented paradigm (OOP).
Please do as I previously suggested: read books, both about the language, and regarding object-oriented design. Before it's even worth continuing, you at least need to understand OOP properly. The FAQ I linked to earlier has some suggestions.
But did you design them? Did you sit down and plan out a specification? Did you isolate candidate classes, data and operations? Did you design test cases, performing unit, integration, and system tests?
No, but I just thought of what I should do as I was coding and when it was finished went through it and upgraded it...
Precisely: those are the bad habits that you should not get accustomed to.
That's a back-handed compliment.
Then thank me ...
A back-handed compliment is nothing to be proud of. You should be apologising to Twey, not asking me to thank you.
[Regarding integer limits] Seriously what chance did I have?
So when I asked you: "Do you understand the limits of those primitive types?", and you replied: "Yep, I do...", you were lying, then? You aren't going to learn if you overestimate your knowledge.
And I don't get ++[var]
What? After explaining it, you said: "OK I see I will peorm some tests in the morni and work it out ..." and you said nothing more about it.
or what you just said
Sigh...
The answer that I was expecting to receive was -2147483648,
Most desktop computers use 32-bit long integers. On these machines, 32-bits allows for a range of [0,4294967295] unsigned, or [-2147483648,2147483647] signed. The variable in the example was signed, so it would have the second range. Because of how these numbers are represented in memory, adding one (1) to 2147483647 (the upper limit) would result in an overflow and wrap around to -2147483648 (the lower limit).
however that would be incorrect: the behaviour is either implementation-specific or undefined.
Whilst what I described would be what often happened, it's not what would always happen so that answer is wrong. Implementation-specific behaviour changes from platform-to-platform: what happens on one type of machine may not happen on another type. Undefined behaviour has no predictable result: it might work as the programmer intended, or flying pigs might appear in the room. Relying on either sort of behaviour is not a good idea.
Fundamental data types in both C and C++ guarantee minimum limits.
The fundamental (basic) data types in C++ are the character (char; plain, signed and unsigned), integer (short, int, and long; signed and unsigned), floating-point (float, double, and long double), boolean (bool), wide character (wchar_t), and void. The C++ Standard states that each of these types must be able to hold certain values, or behave in certain ways. However, the limits aren't absolute: just because an unsigned short integer, for example, must hold at least [0,65535] it could also hold 131071, 262143 or even several billion as a maximum on some machines.
If the example had used an unsigned type, the behaviour would only be implementation-specific as all unsigned integers must obey modulo 2**n arithmetic (where n is the number of bits held by that type).
Unsigned types can never raise an exception. If the value overflows (goes above the maximum limit), it simply wraps around to zero (0). This is what would happen if you always applied a modulus operation (%, in Javascript) after adding.
0 % 10 == 0
1 % 10 == 1
2 % 10 == 2
...
9 % 10 == 9
10 % 10 == 0
11 % 10 == 1
You should already be fairly familiar with the concept... class-based OO is a lot easier to understand from a prototype-based OO background than vice versa. Classes act as a "template" from which objects are built, similar to a constructor function in Javascript.
I AM A BEGGINER AT C++ !
You wrote, or at least implied, that you understood what objects were from scripting. Assuming that you really do, it shouldn't come as a surprise that an object represents a "thing"; a book, a customer, a factory. An object has state (information about that object), and it can send and receive messages (instructions that get or change state). In C++, and other languages, state is stored in data members, and messages are passed using methods. A class, as Twey wrote, is a "template" (I prefer blueprint, to avoid confusion with templates in C++) that lists what members - both for state and messages - there are in an object.
And what's OO?
Object-Oriented programming. Not to be confused with OOP: Object-Oriented Paradigm.
How long is a piece of string?
What's string got to do with this?
What Twey wrote is an expression essentially meaning "It varies" as string can be any length. In other words, C++ may be impossibly complex to some, but fairly trivial to others.
JUst now I have made myself a new policy; to only look up things related to programming.
I should certainly hope that you'll do so: it was a condition of me helping you.
Naturally I hate looking up stuff like words so this is an improvment.
If you don't learn what new words mean, you'll never improve your vocabulary. If you plan to learn how to write software, you'll be doing a lot of reading and you'll have to find out what things mean somehow.
... but really the other reason I don't look up C++ related things is because the site/author doesn't explain the thing in my needed context and this can get frustrating...
Then find another source of information. There's hardly just the one.
pcbrainbuster
05-20-2007, 08:18 PM
Based on what you've written in this thread, none of the words I used should be unfamiliar to you.
They are apparently unfamiliar...
So you wrote: "Of course I have experience with OOP ...", yet you don't actually know what the abbreviation means? That seems rather suspicious to me.
What do you mean by suspicious? And also by reading your post I have relized that I mistook OOP for OO...
Precisely: those are the bad habits that you should not get accustomed to.
Is it alright to quickly plan your project before you start in your mind?
A back-handed compliment is nothing to be proud of. You should be apologising to Twey, not asking me to thank you.
To tell the truth I was joking by saying that you should be thanking me, and by the way Twey I am VERY sorry :(!
So when I asked you: "Do you understand the limits of those primitive types?", and you replied: "Yep, I do...", you were lying, then? You aren't going to learn if you overestimate your knowledge.
By primitive types you wern't just reffering to the variable types?
What? After explaining it, you said: "OK I see I will peorm some tests in the morni and work it out ..." and you said nothing more about it.
I completely forgot about that as I just can't seem to comprehend it, can you please try to explain without using any extra words and get straight to the point, that way it will be easier to understand...
Object-Oriented programming. Not to be confused with OOP: Object-Oriented Paradigm.
Which is exactly what happend to me :)...
questions :
1) Am I right in saying certain types of variables take more memory then others to use?
2) To put text into a variable, you have to use string object then the variable right?
3) Thing like cout, cin, string etc are called objects right?
mwinter
05-20-2007, 11:32 PM
Object-Oriented programming. Not to be confused with OOP: Object-Oriented Paradigm.
Hmm. Disregard that. Whilst I consider object-oriented programming and the object-oriented paradigm to be two different things, you're more likely to find them used to mean the same thing elsewhere.
They are apparently unfamiliar...
As I wrote, they shouldn't be. An introduction to C++ should also include an introduction to OOP; you should have covered it in the first hour.
What do you mean by suspicious?
Odd. Raises questions.
Is it alright to quickly plan your project before you start in your mind?
Depends on the complexity of the project. Something trivial won't really need any planning. However, anything even remotely complicated needs testing, and that requires detailed thought about how it should work.
By primitive types you wern't just reffering to the variable types?
By primitive types, I meant the fundamental types I listed in my previous post. However, I asked if you understood the limits of those types: the range of values they can hold, and what happens outside of those ranges.
... can you please try to explain [postfix and prefix increment and decrement] without using any extra words and get straight to the point, that way it will be easier to understand...
You didn't understand the direct approach, but I'll try again once more. Both prefix increment (++var) and postfix increment (var++) add 1 to a variable: the value of the variable is read, increased by one, then assigned back to the variable. No problem so far, I hope.
Apart from changing the value of a variable, the expressions ++var and var++ have values. This value can be assigned to a variable, or used with other operators. The value of the expression ++var is the value of var after 1 has been added. The value of the expression var++ is the value of var before 1 has been added; the original value of var.
That's it. Nothing more.
1) Am I right in saying certain types of variables take more memory then others to use?
Yes, of course. However, the amount of memory (in bits) for a given type varies from platform to platform.
You probably won't cope with a full answer at the moment.
2) To put text into a variable, you have to use string object then the variable right?
In "plain" C++ (without the use of third-party libraries or user-defined types), there are two main ways of storing text. The first is the const char array, usually expressed as a pointer to the first character in the array:
const char* text = "The quick brown fox jumps over the lazy dog.";
All strings created in this way end with a null character '\0' (ASCII value 0). The second way is using an object of the std::string class:
std::string text("The quick brown fox jumps over the lazy dog.");
Both examples create a variable named text representing the same sequence of characters, but with two different types.
3) Thing like cout, cin, string etc are called objects right?
No, not quite. In my second example above, text is an object of type std::string, and std::string is a class. Both std::cout and std::cin are objects. The first is of type std::ostream, and the second is of type std::istream.
Classes define types. Objects are instances of classes: the actual representation in memory. There can only be one class for a given type, but there can be many objects created from one class.
pcbrainbuster
05-21-2007, 05:18 PM
As I wrote, they shouldn't be. An introduction to C++ should also include an introduction to OOP; you should have covered it in the first hour.
I'll look it up, now...
You didn't understand the direct approach, but I'll try again once more. Both prefix increment (++var) and postfix increment (var++) add 1 to a variable: the value of the variable is read, increased by one, then assigned back to the variable. No problem so far, I hope.
Apart from changing the value of a variable, the expressions ++var and var++ have values. This value can be assigned to a variable, or used with other operators. The value of the expression ++var is the value of var after 1 has been added. The value of the expression var++ is the value of var before 1 has been added; the original value of var.
That's it. Nothing more.
Woohoo I get it!, but there is one thing I need to know regarding this, once you actually post/prefix a variable does it values go up by one no matter what it may display at first?
In "plain" C++ (without the use of third-party libraries or user-defined types), there are two main ways of storing text. The first is the const char array, usually expressed as a pointer to the first character in the array:
I havn't learnt arrays or pointers :(...
Both examples create a variable named text representing the same sequence of characters, but with two different types.
Can't I just use std::string="" instead of ("")?
No, not quite. In my second example above, text is an object of type std::string, and std::string is a class. Both std::cout and std::cin are objects. The first is of type std::ostream, and the second is of type std::istream.
Classes define types. Objects are instances of classes: the actual representation in memory. There can only be one class for a given type, but there can be many objects created from one class.
Grrrr, sorry man just lost you here :(:(!
questions:
1) How do you remember what everything is called (eg pointers, members...)?
If you wanted to represent, say, a stack of CDs, you'd have one CD class which represented how a CD looks and behaves, then a number of instances of that class, one for each actual CD.
mwinter
05-21-2007, 07:49 PM
Woohoo I get it!, but there is one thing I need to know regarding this, once you actually post/prefix a variable does it values go up by one no matter what it may display at first?
The addition is always applied, yes.
Whilst the addition is always applied (or subtraction, in the case of the decrement version), the value may not necessarily increase. Remember that integer types have limits and increasing the value above the upper limit may cause it to wrap around to the lower limit (or vice versa), or raise an exception.
I havn't learnt arrays or pointers :(...
Both will take some time to explain and best done, in my opinion, with illustrations. I started writing a description, but I realised it would take too long. They aren't important concepts (yet), so you can leave them for a while and read about them at your leisure.
Can't I just use std::string="" instead of ("")?
You could, but shouldn't. Assigning the value...
std::string text = "The quick brown fox jumps over the lazy dog.";
is inefficient.
What actually happens is that a std::string object is created using the default constructor. This is an empty string. The assignment then invokes (calls) the assignment operator (operator=(const char*)), overwriting the value. It's better to use the std::string(const char*) constructor, initialising the object properly from the start.
How do you remember what everything is called (eg pointers, members...)?
That's what I do when I learn: remembers things. :)
pcbrainbuster
05-21-2007, 08:44 PM
That was so easy to understand :p No prob :)...
Anyway learning how to use arrays was no problem and I understand the basic version while the multidimensional version raises a question...
here is an example -
#include <iostream>
using namespace std;
int main ()
{
int MyArray [] = {1, 2, 3, 4, 5}; // I understand that ifrst index is 0
cout << MyArray[0] << endl; // 1
MyArray [1] = 9
cout << MyArray[1] << endl; // 9
int valuehold = MyArray[4]
cout << valuehold << endl; // 5
cin.get() // Results; to see them...
}
Well do you htink I understand the concept?
questions:
1) Is it even important for me to know multidimensional arrays?
mwinter
05-21-2007, 09:52 PM
std::string text = "The quick brown fox jumps over the lazy dog.";
...
What actually happens is that a std::string object is created using the default constructor. This is an empty string. The assignment then invokes (calls) the assignment operator (operator=(const char*)), overwriting the value. It's better to use the std::string(const char*) constructor, initialising the object properly from the start.
Sorry, that's not quite right. The description above is for the code:
std::string text;
text = "The quick brown fox jumps over the lazy dog.";
However, the process for the original isn't that much better: a temporary std::string object is created using the literal (using the std::string(const char*,const Allocator&=Allocator()) constructor), and then assigned using the copy assignment operator (operator=(const std::string&)). An implementation may skip the temporary object, but then again, it may not; using a parenthesised initialiser is more reliable.
I told you I was a little rusty... :o
Well do you htink I understand the concept?
Maybe. Answer a couple of questions and we'll see.
How are arrays organised in memory?
How many types of data can one array hold?
What happens (or needs to happen) if you need a larger array than has been allocated?
1) Is it even important for me to know multidimensional arrays?
It doesn't hurt, though arrays in general are usually replaced by STL container classes, like std::vector and std::list.
pcbrainbuster
05-22-2007, 04:09 PM
...However, the process for the original isn't that much better: a temporary std::string object is created using the literal (using the std::string(const char*,const Allocator&=Allocator()) constructor), and then assigned using the copy assignment operator (operator=(const std::string&)). An implementation may skip the temporary object, but then again, it may not; using a parenthesised initialiser is more reliable.
I told you I was a little rusty...
Well it happens to the best of us :p. Anyway whats a constructor, destructor?
Maybe. Answer a couple of questions and we'll see.
How are arrays organised in memory?
How many types of data can one array hold?
What happens (or needs to happen) if you need a larger array than has been allocated?
To tell the truth, I don't even attempt to memorize additional information on stuff but rather the main thing it self. In this case I learned how to use the main version of arrays but did not learn the answers to those questions. I do realize this is a bad habit, but I have to memorize the main information first then move on to the additional. I have chosen to go this way.
It doesn't hurt, though arrays in general are usually replaced by STL container classes, like std::vector and std::list.
Uhhhh?
question:
1) When I create a function, do I have to declare it like this (type function(possible arguments)) before int main() unless I created the function itself before int main()?
Have a look at Binky's Pointer Fun (http://cslibrary.stanford.edu/104/), I found it quite amusing and it might even help you grasp the concept :p
Anyway whats a constructor, destructor?A constructor (ctor for short) is a function that's called when a new instance of a class is created. It usually handles setting up the class properly for use. Destructors (or dtors) are functions called when a class is destroyed. They're mostly used for reclaiming memory used by the class.
Uhhhh?Just what he said -- static arrays aren't really very useful in most cases. Vectors and lists can do everything arrays can, but can also be extended by simply adding new elements onto the end, rather than having to create a whole new array (answer to Mike's question #3, sorry Mike).
1) When I create a function, do I have to declare it like this (type function(possible arguments)) before int main() unless I created the function itself before int main()?Not usually, if I remember correctly. It's always good practice, though.
pcbrainbuster
05-22-2007, 06:20 PM
Have a look at Binky's Pointer Fun, I found it quite amusing and it might even help you grasp the concept
Thanks, I'm currently downloading it...
A constructor (ctor for short) is a function that's called when a new instance of a class is created. It usually handles setting up the class properly for use. Destructors (or dtors) are functions called when a class is destroyed. They're mostly used for reclaiming memory used by the class.
I currently don't understand classes so I do not understand this, yet :)...
Just what he said -- static arrays aren't really very useful in most cases. Vectors and lists can do everything arrays can, but can also be extended by simply adding new elements onto the end, rather than having to create a whole new array (answer to Mike's question #3, sorry Mike).
I guess I will look it up at some point after the basics if I remember...
Not usually, if I remember correctly. It's always good practice, though.
What do you mean :confused:...
pcbrainbuster
05-22-2007, 06:52 PM
Thanks, I'm currently downloading it...
I watched it and here is a script I wrote based on it -
#include <iostream>
using namespace std;
int main ()
{
int* x = new int;
int* y = new int;
*x = 1;
*y = 2;
cout << x << " : The value of pointer x..." << endl << y << " : The value of pointery";
cin.get();
}
Though I just don't see the point of pointers... Thanks though :).
question:
1) What is new int?
mwinter
05-22-2007, 08:11 PM
[What's] a constructor, destructor?
Twey provided a good overview, but I'll come back to this subject later.
To tell the truth, I don't even attempt to memorize additional information on stuff but rather the main thing it self.
So long as you cover it before starting major work in the language. A lot of what seems like small details can have a massive affect on how a program will work, or the way you'd write something.
1) When I create a function, do I have to declare it like this (type function(possible arguments)) before int main() unless I created the function itself before int main()?
The rule is "declare before first use". What this means is that before code tries to use something, whether it's a class, variable, or function, that something must have been declared. That's why header files are used: the header contains declarations, and the compiler must have seen those declarations before your code tries to use whatever that header is for.
The following example is illegal:
void foo() {
bar();
}
void bar() {}
int main() {
foo();
return 0;
}
The reason is that the first function, foo, references the second function, bar, before the latter has been declared. One fix, you can probably guess:
void bar(); // Declare function: bar
void foo() {
bar();
}
void bar() {}
int main() {
foo();
return 0;
}
The other would have been to reorder the function definitions so that bar appeared before foo, however it's not always possible to make changes like that.
Destructors (or dtors) are functions called when a class is destroyed.
When an object is destroyed. :)
Vectors and lists can do everything arrays can, but can also be extended by simply adding new elements onto the end, rather than having to create a whole new array (answer to Mike's question #3, sorry Mike).
Don't worry, I'd have answered #3 if I'd explained std::vector and std::list.
I currently don't understand classes so I do not understand this, yet :)...
The concept of a class is very simple: it defines a type.
You're familiar with integers (the int type, and friends). They can be considered objects in a way - in fact, that's exactly what they are, according to the C++ Standard. Integers have state: the number value. Integers also have behaviour: arithmetic (addition, subtraction, etc.) and comparison. The same can be said of all objects: state and behaviour, combined.
A class is a type; a blueprint for an object. It lists the data that makes up state, and the methods (and operators!) that define the behaviour. As a programmer, you create classes to represent parts of the system you are trying to create: if you were modelling a computer, for example, you'd create classes to represent the CPU, memory, hard disks, and so on.
As Twey wrote, a constructor sets up an object. When you create an object from a class, you need to make sure that the pieces of data have some sensible, predictable initial values, and you do this by assigning values in the constructor. The destructor of an object is called when the object is about to be destroyed, and tidies up after the object. For example, if the object allocated memory, the destructor can be used to release the memory, giving it back to the operating system. Similarly, if the object opened a file, the destructor would make sure that the file was closed.
I watched it and here is a script ...
You write programs, not scripts, with C++. :cool:
#include <iostream>
using namespace std;
int main ()
{
int* x = new int;
int* y = new int;
*x = 1;
*y = 2;
You could have also written:
int* x = new int(1);
int* y = new int(2);
cout << x << " : The value of pointer x..." << endl << y << " : The value of pointery";
cin.get();
}
Ouch! You just created a memory leak. It was short-lived, but there, nevertheless.
Whenever you allocate memory (which is what the new operator does), make sure that you delete it with the delete operator once you've finished with that memory. It's also a good habit to null pointers after they've been used by assigning zero (0). Trying to use a null pointer will terminate the program, but at least you know there's a problem; using old pointer values (termed "dangling pointers") can lead to more subtle bugs that are difficult to find.
#include <iostream>
int main() {
int* x = new int(1);
int* y = new int(2);
std::cout << "Value of pointer x: " << x << "\nPointer x dereferenced: " << *x
<< "\n\nValue of pointer y: " << y << "\nPointer y dereferenced: " << *y << std::endl;
delete x;
x = 0; // Null pointer
delete y;
y = 0;
std::cin.get();
return 0;
}
Though I just don't see the point of pointers...
One thing that pointers have been used for in the past is to refer to something. Consider passing data to a function. The normal way of passing arguments is by value. This requires allocating space for the object and then copying the data into that space. For a large object, this can take a long time. However, with a pointer, all that you copy is the address; a number. Much quicker. In C++, you can use references which are similar to pointers, but safer to use. However, C++ has is roots in C, so that's one reason that pointers are still used.
Another very common reason for pointers is demonstrated in the code you posted: allocating memory. The new operator returns an address - a pointer - to the area of memory that was allocated. If the allocation fails, a null pointer is returned (though in C++, an exception can be thrown, instead).
I'll leave it there, for now.
pcbrainbuster
05-23-2007, 03:25 PM
Twey provided a good overview, but I'll come back to this subject later.
I dought you will remember :p
So long as you cover it before starting major work in the language. A lot of what seems like small details can have a massive affect on how a program will work, or the way you'd write something.
What do you mean?
You write programs, not scripts, with C++.
I can't say heres my program and then give a code but not a download, or can I? It makes no sense :confused:...
...I'll leave it there, for now.
I guess I understand pointer a little now except for the new int(number) part but I still do not see te true advantage for it other then a small amount of extra efficiency...
questions:
1) What is void exactly, as far as I understand it means nothing...
2) Can you seriously virtually do anything on a computer with C++?
1) What is void exactly, as far as I understand it means nothing...That's exactly what it means :) void is a type that literally means no type at all. For example, if you wanted a function that didn't return a value, you'd declare it to return void. Another occasionally handy (but usually ugly) trick with pointers is to create a void pointer:
void *ptr;A void pointer can point to anything. You need to cast it back to its correct type before doing anything with it, though.
int *myint = new int(5);
void *ptr = (void*)myint;
std::cout << *((int*)ptr);
2) Can you seriously virtually do anything on a computer with C++?One can do "anything" on a computer using any Turing-complete language. Various languages make it easier or harder to express various concepts, but they're all capable of it. A lot of libraries were written in or have bindings for C and/or C++, so it does tend to simplify using them.
I can't say heres my program and then give a code but not a download, or can I?Of course you can.
I still do not see te true advantage for it other then a small amount of extra efficiency...It's not a small amount at all: a pointer can, in a usual situation, be anything between ten and ten thousand times smaller than the actual object. In extreme situations, large programs and so on, with objects that store very large amounts of data, an object can be far bigger still. Then, if that object references other objects, if we're not using pointers those all have to be copied across too, and any objects they reference, and any objects they reference... it quickly becomes a nightmare. A machine would run out of memory very quickly.
Yet another use of pointers is to reference other memory locations by location relative to one. That's what happens with arrays. An array is actually just a pointer. If you have:
myType myArray[10];you're saying "allocate space for ten instances of myType and set myArray to be a pointer to the first one." When you do:
myArray[x];you're saying "the myType-sized block of memory at the location of myArray plus the size of x instances of myType."
pcbrainbuster
05-23-2007, 05:36 PM
OK I see, but why did you put anything in quotes?
Because obviously "anything" on a computer isn't exactly anything that can possibly be imagined. One is limited by the hardware and the laws of physics.
mwinter
05-23-2007, 09:02 PM
Twey provided a good overview, but I'll come back to [constructors and destructors] later.
I dought you will remember
The question is: did it help? If not, be specific about what you don't understand.
So long as you cover it before starting major work in the language. A lot of what seems like small details can have a massive affect on how a program will work, or the way you'd write something.
What do you mean?
These "small details" can make the difference between a program that works, and one that fails (or worse, one that fails occasionally!). Those details may also reveal a better way of achieving a particular goal; a simpler or more efficient approach.
You write programs, not scripts, with C++.
I can't say heres my program and then give a code but not a download, or can I?
You could attach an executable (in a Zip archive), though Twey, for instance, may not be able to run it if he's using Linux at the time (assuming you use, and target, Windows).
Regardless, I was referring to concept of scripts versus programs. A script is interpreted by some other program, usually to enhance what that program can do - browser scripting, for instance. A program, however, is software in its own right; more powerful, and independent.
I guess I understand pointer a little now except for the new int(number) part
As I wrote previously, the new operator allocates memory, and takes it from the heap (or free store). The operator is followed by a type name. The type tells the operator how much space is needed. After that, there's an optional initialiser (the parenthesised part). If the initialiser isn't present, the newly allocated memory is set to the default value for that type. If the initialiser is present, the memory is set accordingly. For integers, the initialiser is simply a whole number.
but I still do not see te true advantage for it other then a small amount of extra efficiency...
For C++ code, you'll mostly use references, rather than pointers, to avoid passing by value when calling functions or methods. You'll only need pointers when allocating memory. However, if you have to interact with C code, such as with the Win32 API, you'll be using pointers a lot as they are the only way in which passing by reference can be accomplished.
1) What is void exactly, as far as I understand it means nothing...
More-or-less. As a return type, void means that the function returns nothing. Within the parameter list of a function declaration or definition, void means no arguments:
int main(void) {/* ... */}
is the same as:
int main() {/* ... */}
but the latter is preferred. You'll see the first form used with C.
A void pointer can point to anything. You need to cast it back to its correct type before doing anything with it, though.
Beware: casting from void* to a specific type can be dangerous. It's essentially the same as up-casting. Avoid it completely if possible - templates can sometimes help here.
pcbrainbuster
05-24-2007, 04:13 PM
The question is: did it help? If not, be specific about what you don't understand.
I simply ujnderstand no part of it, including (still) what its job is...
These "small details" can make the difference between a program that works, and one that fails (or worse, one that fails occasionally!). Those details may also reveal a better way of achieving a particular goal; a simpler or more efficient approach.
I get it but still, I want to give myself some confidence by learning the main part :)...
For C++ code, you'll mostly use references, rather than pointers, to avoid passing by value when calling functions or methods. You'll only need pointers when allocating memory. However, if you have to interact with C code, such as with the Win32 API, you'll be using pointers a lot as they are the only way in which passing by reference can be accomplished.
I guess I see the advantage :p.
Beware: casting from void* to a specific type can be dangerous. It's essentially the same as up-casting. Avoid it completely if possible - templates can sometimes help here.
I don't really know what up-casting or templates are :(, sorry...
questions -
1) I don't really get the whole return type concept of a function as I don't use return(num) at all...
2) Is there any difference between win32 programming and console based programming in terms of power?
3) What is a struct?
You could attach an executable (in a Zip archive), though Twey, for instance, may not be able to run it if he's using Linux at the time (assuming you use, and target, Windows).wine will probably handle such a simple program without any problems.
Beware: casting from void* to a specific type can be dangerous. It's essentially the same as up-casting. Avoid it completely if possible - templates can sometimes help here.I did say it was usually ugly. Quite a few libraries make use of it, though: I'm thinking pthreads in particular.
1) I don't really get the whole return type concept of a function as I don't use return(num) at all...Then you're probably writing bad programs, or just small ones. Returning values is very useful to avoid repeating one's self, and I'm rather surprised you haven't run into the concept in Javascript already.
2) Is there any difference between win32 programming and console based programming in terms of power?No. Stop differentiating between these two. It's the same language either way, they're just different methods of outputting the results.
3) What is a struct?An area of memory that holds multiple values. You can think of it as a class that can't hold methods (although it can hold function pointers, which is one way of hacking together a very basic form of object-orientation in C).
pcbrainbuster
05-24-2007, 07:16 PM
Then you're probably writing bad programs, or just small ones. Returning values is very useful to avoid repeating one's self, and I'm rather surprised you haven't run into the concept in Javascript already.
Exceptas far as I remember it only had two return values; 1 meaning something like yes and 2 means something like no, remember yes and no are being used as references...
An area of memory that holds multiple values. You can think of it as a class that can't hold methods (although it can hold function pointers, which is one way of hacking together a very basic form of object-orientation in C).
How would I use in a sentence?
Exceptas far as I remember it only had two return values; 1 meaning something like yes and 2 means something like no, remember yes and no are being used as references...If you're going to do that, use boolean true and false.
How would I use in a sentence?Use what in a sentence?
pcbrainbuster
05-25-2007, 06:35 AM
Use what in a sentence?
Struct, how do you use it in a sentence?
mwinter
05-25-2007, 06:39 PM
I simply ujnderstand no part of [the recent class explanation], including (still) what its job is...
That would mean that there hasn't been a single sentence that you understand. To be frank, if that's the case, give up (for) now. There's no point in using C++ if you cannot grasp classes.
I don't really know what up-casting or templates are :(, sorry...
I didn't expect you to: up-casting requires knowledge of classes and inheritance, and you aren't ready for generics, yet.
1) I don't really get the whole return type concept of a function as I don't use return(num) at all...
Everything in C++ has a type. The return type in a function declaration states what type of value the function sends back to the caller. There's no much there to "get".
wine will probably handle such a simple program without any problems.
I'd be surprised if it didn't, but that doesn't mean that you actually have it installed (or would be willing to do so). :)
Quite a few libraries make use of [void pointers], though: I'm thinking pthreads in particular.
Heck, the new operator itself returns a void pointer, but one would rarely assign the returned address to such a variable.
You can think of [structs] as a class
From a literal point-of-view, a struct is a class, only with different default member access. Conceptually, things are slightly different. See, for instance, the C++ FAQ (Lite) entry, What's the difference between the keywords struct and class? (http://www.parashift.com/c++-faq-lite/classes-and-objects.html#faq-7.8).
pcbrainbuster
05-25-2007, 07:13 PM
That would mean that there hasn't been a single sentence that you understand. To be frank, if that's the case, give up (for) now. There's no point in using C++ if you cannot grasp classes.
NOOOO WAY! When you sai that it made me feel part dead :p but anyway I will push hard to understand the concept! Don't worry sen-sei I will do good. Besides I just had a weeks holiday starting today!
I didn't expect you to: up-casting requires knowledge of classes and inheritance, and you aren't ready for generics, yet.
I have no idea what generics are but as I said I will search it!!!
Everything in C++ has a type. The return type in a function declaration states what type of value the function sends back to the caller. There's no much there to "get".
What I tried to point out is that I tend to not use return(num) and apparently it works fine, so what I am trying to say is that at what point does the function/(or any other thing with a type) have a number returned?
generics = Something used in programming languages that allows the programmer to use functions/object/etc without specifing any type so it can be used as many times over for more then one situation (its like defining the same function/etc man times over each with the same code but different type but better/more efficient)
I'd be surprised if [wine couldn't handle so simple a program], but that doesn't mean that you actually have it installed (or would be willing to do so). :)Alas yes, I do occasionally have to run programs designed for Windows. I do minor Windows development from time to time as well, so I have a cross compiler too, although there's not usually much to test because I (try to) keep things as platform-agnostic as possible.
I have no idea what generics are but as I said I will search it!!!That's not really the correct reaction when someone tells you you're not ready to understand them yet :p Unless you have a working knowledge of classes and inheritance and polymorphism as approached from a class-based point of view, whatever you may find won't make an iota of sense to you.
What I tried to point out is that I tend to not use return(num) and apparently it works fine, so what I am trying to say is that at what point does the function/(or any other thing with a type) have a number returned?If you don't return from a function that has its return type defined as int, I think it returns 0. Ditto with bool and false, if I remember correctly.
pcbrainbuster
05-25-2007, 08:39 PM
Alas yes, I do occasionally have to run programs designed for Windows. I do minor Windows development from time to time as well, so I have a cross compiler too, although there's not usually much to test because I (try to) keep things as platform-agnostic as possible.
Don't know what platform-agnostic is but I guess I will look it up aswell!!!
That's not really the correct reaction when someone tells you you're not ready to understand them yet Unless you have a working knowledge of classes and inheritance and polymorphism as approached from a class-based point of view, whatever you may find won't make an iota of sense to you.
You never give up your passion!!! :p Besides I love programming to much to give it up!
I guess I should tell you this but starting now I use "!" to show enthusiasm rather then anger(":mad:")...
If you don't return from a function that has its return type defined as int, I think it returns 0. Ditto with bool and false, if I remember correctly.
OK, thats the answer I was looking for...
platform-agnostic = Something that does not rely on a specific computer system but rather something that works on all major systems (OSs(Operating Systems))
Don't know what platform-agnostic is but I guess I will look it up aswell!!!The principle that the code shouldn't need to know on which platform it is running, and should compile and run equally well on any platform. With low-level code this isn't always entirely possible to achieve, however.
I guess I should tell you this but starting now I use "!" to show enthusiasm rather then anger(":mad:")...Your sentence doesn't make much sense.... 'But' is a contrasting conjunctive; that is to say, 'x but y' means 'y even though x' or 'y in contrast to x:' x and y are in opposition, such as 'it was difficult, but John won the marathon,' indicating that it being difficult had a negative effect on the likelihood of John winning the marathon, or 'Paul went to snooker, but Irene went swimming' in which the two actions contrast simply because Irene is doing something that Paul isn't. You, however, say that you should tell us, then go ahead and tell us: your two statements are in agreement. Thus, 'but' is not the correct conjunctive, suggesting that one of the statements is wrong.
The impression I got was that you actually meant to type 'I guess I shouldn't tell you this,' but I can think of no reason that that would be explicitly stated either. You could also have meant to somehow expand on the fact that you refuse to tell us in your second statement. Alternatively, you could have been incorrect in using 'but;' if you wish to join two statements that are in agreement, you can use a syntactic-descriptive colon, as in 'I guess I should tell you this: starting now I use "!" to show enthusiasm' where the clause after the colon is a clarification of the word 'this.' Another option is to introduce a clause using 'that:' 'I guess I should tell you that starting now I use "!" to show enthusiasm.'
pcbrainbuster
05-25-2007, 09:50 PM
Your sentence doesn't make much sense.... 'But' is a contrasting conjunctive; that is to say, 'x but y' means 'y even though x' or 'y in contrast to x:' x and y are in opposition, such as 'it was difficult, but John won the marathon,' indicating that it being difficult had a negative effect on the likelihood of John winning the marathon, or 'Paul went to snooker, but Irene went swimming' in which the two actions contrast simply because Irene is doing something that Paul isn't. You, however, say that you should tell us, then go ahead and tell us: your two statements are in agreement. Thus, 'but' is not the correct conjunctive, suggesting that one of the statements is wrong.
The impression I got was that you actually meant to type 'I guess I shouldn't tell you this,' but I can think of no reason that that would be explicitly stated either. You could also have meant to somehow expand on the fact that you refuse to tell us in your second statement. Alternatively, you could have been incorrect in using 'but;' if you wish to join two statements that are in agreement, you can use a syntactic-descriptive colon, as in 'I guess I should tell you this: starting now I use "!" to show enthusiasm' where the clause after the colon is a clarification of the word 'this.' Another option is to introduce a clause using 'that:' 'I guess I should tell you that starting now I use "!" to show enthusiasm.'
Oh my god! I have never read anything so confusing in my life! But don't worry I understood what you meant byone of the lines, and yeah you are right I did mean to say "I guess I should tell this, starting now I use "!" to show enthusiasm rather then anger(":mad:")...". I tend to right fast andnot read over which in turn causesmany typos/accidents...
mwinter
05-25-2007, 11:57 PM
What I tried to point out is that I tend to not use return(num) and apparently it works fine, so what I am trying to say is that at what point does the function/(or any other thing with a type) have a number returned?
A function returns either at a return statement, or when execution reaches the end of the function body, just the same as in ECMAScript.
generics = Something used in programming languages that allows the programmer to use functions/object/etc without specifing any type so it can be used as many times over for more then one situation (its like defining the same function/etc man times over each with the same code but different type but better/more efficient)
Something like that. Consider the simple case of a min function:
int min(int a, int b) {
return (a < b) ? a : b;
}
Fine, but what if you need the smaller of a float or an instance of some user-defined type? C++ has strict typing rules that would prevent the use of the function above, or require casting and a potential loss of data. One option is to copy the function and change the return type and argument types, but that becomes annoying if it needs to be done several times. The alternative is to use templates:
template <typename T>
const T& min(const T& a, const T& b) {
return (a < b) ? a : b;
}
This one function can handle any type - so long as the less-than operator means something, of course. Templates also work with classes, and this is what the STL is: Standard Template Library. In fact, it defines the code above - exactly I have (but within the std namespace) or something functionally equivalent.
If you don't return from a function that has its return type defined as int, I think it returns 0. Ditto with bool and false, if I remember correctly.
Behaviour is undefined:
Flowing off the end of a function is equivalent to a return with no value; this results in undefined behavior in a value-returning function.
—6.6.3 The return statement, ISO/IEC 14882:2003
With the formal definition of "undefined behaviour", this should lead to one of three probable outcomes:
The return value will be of some random value: whatever happened to be in the appropriate location in memory at the time.
During translation of the program, a definite value (such as zero) will be used, with or without the issuance of a diagnostic.
Translation of the program will fail and a diagnostic will be issued.
Clearly, as with all undefined behaviour, this isn't desirable: computer programs should be predictable.
boxxertrumps
05-26-2007, 04:41 AM
Someone said something about multithreading...
http://freshmeat.net/projects/libhoard/?branch_id=4119&release_id=254349
FOR THE HOARD!!!
pcbrainbuster
05-26-2007, 08:36 PM
I am just wondering if this is possible, say you had a hard drive which had secret military files in it and you needed to protect it with a password, can C++ make the user input a password everytime he/she tries to access the directory or any of its files?
djr33
05-26-2007, 08:41 PM
Well.... that's not quite possible.
You could create a C++ program that would only allow access to the files with a certain password, but just going onto the harddrive itself, directly to the files, would get around this.
Therefore, you'd need to make the C++ program be the only way to access the files.
There are several options:
1. You could encrypt the files and have the C++ program know how to decrypt them, so the password would either decrypt all the files or just allow temporary access and leave the originals encrypted.
2. You could create a C++ program in which the files and folders were embedded, so it would be like a self extracting zip archive, but with a required password before it would do anything.
3. You could make some weird filesystem/harddrive setup/etc and then create a driver that would force a password before it allowed access. This is complex and you'd need more than just C++, but that could be part of it.
Basically, whatever you do will involve some sort of encryption as anything can be read byte for byte if you have enough time/need to do so. If it isn't encrypted, than this method, though tedious, would reveal everything anyway.
Along with encryption comes the dangers of it being broken. The government spends a huge amount of money constantly developing new methods of encryption, so don't think you could code something better. At the same time others (and likely the government itself) create complex decryption programs that try to break decryption, so that's out there as well.
pcbrainbuster
05-26-2007, 10:52 PM
Another question that pops in my head is that how do programs when clicked on automatically open other programs that ask for a password before it opens? Also how do certain programs only have one file (itself) and it has songs pictures and all tht being used?
Here is a better example -
One file, click on it, it opes up, it has bitmaps sounds and all that!!! You go back ois old folder to believe that it uses only one file, and that ile is the exectuable itself!!!
djr33
05-27-2007, 01:31 AM
In the command prompt, "start ___.ext" works, or, for programs, you can just type "___", no need for the .exe, even.
In the same sense, a program can do it. I'm not sure about other languages, or what it is in binary once compiled, but this is a pretty basic command.
A password is just part of the program. If pass=='test', then it continues. Or something like that.
Programs can access the data from other files.
Think about PHP... same thing, but different functions, etc.
In the same sense, many programs do have multiple files and folders, such as logs, plugins, organized components that could be included but were left out for some reason (perhaps to be able to customize), .dll's and other system files, etc.
pcbrainbuster
05-27-2007, 01:59 AM
Sorry man but I completely lost you, sorry about that :(...
tech_support
05-27-2007, 05:50 AM
it has bitmaps sounds and all that!!!
Huh?
World's most annoying application ever! :p
You go back ois old folder to believe that it uses only one file, and that ile is the exectuable itself!!!
Me lost.
tech_support
05-27-2007, 05:51 AM
What djr33 means is that, you run the command "start" on the Command Prompt.
eg. start notepad.exe
djr33
05-27-2007, 07:40 AM
Why, after 15 pages, have you not just found yourself a tutorial?
I think what I explained above is quite clear. If not, I'd suggest... well... a tutorial.
If you just learned the language, all of these random questions would become easy. Using outside resources, for example, as per your question, is a standard task and should be covered in a tutorial, at least once you reach that level.
pcbrainbuster
05-27-2007, 11:50 AM
Why, after 15 pages, have you not just found yourself a tutorial?
Actually a tutorial is what started me asking the question :p...
I think what I explained above is quite clear. If not, I'd suggest... well... a tutorial.
At first I got confused as I thought that start and __ was together but when I realized that was not the case it became understandable...
If you just learned the language, all of these random questions would become easy. Using outside resources, for example, as per your question, is a standard task and should be covered in a tutorial, at least once you reach that level.
Actually to tell the truth I did not really have time to acutally learn C++ but I kept forcing my self, its all cause of school, all that homework usually wastes my life at a new whole level... But right now I have around a wees of holiay and am actually starting to get some where, notice how I did not know the meanings of things like platform-agnostic and generics but now I understand 'em like they are everyday words :)...
question-
1) At this other site I just read that the standard starting function is main() even for GUI based programs! Is this true?
1) At this other site I just read that the standard starting function is main() even for GUI based programs! Is this true?Depends. win32 programs have a WINMAIN function instead. All other types of program of which I know, though, use the standard main(), including those that use various toolkits to provide a GUI.
pcbrainbuster
05-27-2007, 04:48 PM
#include <iostream>
using namespace std;
int operate(int operationb, int no1, int no2)
{
if (operationb==1) {return no1+no2;}
else if (operationb==2) {return no1-no2;}
else if (operationb==3) {return no1*no2;}
else if (operationb==4) {return no1/no2;}
return 0;
}
int main()
{
int operationa, num1, num2;
cout << "Hello, and welcome to Matahir Shah's program.\nThis is a simple calculator which supports -\n- Addition\n- Subtraction\n- Multiplication\n- Division" << endl << endl;
cin.get();
cout << "First of all choose your operation -\nPress 1 for addition, 2 for subtraction, 3 for multiplication and 4 for division\n";
cin.get();
cin >> operationa;
cin.ignore();
cout << "\n\nNow that you have chosen your operation, input a number followed by a space and another number to operate on -" << endl;
cin.get();
cin >> num1 >> num2;
cout << "\n\nAnd the answer is: " << operate(operationa, num1, num2);
cin.get();
return 0;
}
Whats wrong guys, sigh?
Most obviously, too many cin.get()s. None of those are actually necessary.
#include <iostream>
int operate(char operationb, int no1, int no2)
{
switch(operationb) {
case '+':
return no1 + no2;
case '-':
return no1 - no2;
case '*':
return no1 * no2;
case '/':
return no1 / no2;
}
return 0;
}
int main()
{
int num1, num2;
char operation;
std::cout
<< "Hello, and welcome to Matahir Shah's program." << std::endl
<< "This is a simple calculator which supports:" << std::endl
<< "\t- Addition" << std::endl
<< "\t- Subtraction" << std::endl
<< "\t- Multiplication" << std::endl
<< "\t- Division" << std::endl
<< std::endl;
while(operation != 'n') {
std::cout
<< std::endl
<< "Input the operation and operands, separated by spaces: ";
std::cin
>> num1
>> operation
>> num2;
std::cout
<< std::endl
<< std::endl
<< "And the answer is: "
<< operate(operation, num1, num2)
<< std::endl;
operation = 0;
std::cout << "Perform again? (Y/n): ";
std::cin >> operation;
}
return 0;
}
pcbrainbuster
05-27-2007, 09:07 PM
#include <iostream>
using namespace std;
int calculate(int num1b, char operatorb, int num2b)
{
if (operatorb=="+") {return num1b+num2b;}
else if (operatorb=="-") {return num1b-num2b;}
else if (operatorb=="*") {return num1b*num2b;}
else if (operatorb=="/") {return num1b/num2b;}
return 0;
}
int main()
{
int num1a, num2a;
char operatora;
cout << "Hello, and welcome to Matahir Shah's program.\nThe program is a basic calculator which supports the following:\n- Addition\n- Subtraction\n- Multiplication\n- Division" << endl << endl;
cin.get();
while (operatora!="n")
{
cout << "Type a number followed by a operator and another number -" << endl;
cin >> num1a >> operatora >> num2a;
cout << "\n\nYour answer is: " << calculate(num1a, operatora, num2a) << endl;
cin.get();
cout << "Are you finished (y/n)?";
cin >> operatora;
}
}
I realized I have issues with letters and sentences in variables, anyone mind helpin' me out with it?
pcbrainbuster
05-27-2007, 09:51 PM
Today I learned what recursions are; basically a recursion is when a function is looped...
eg
void crimeRate(int rate)
{
crimeRate(rate-1)
}
int main()
{
crimeRate(10)
}
Though the site failed to show the usefullness of recursion and so I need someone to explain the usefullness...
void crimeRate(int rate)
{
crimeRate(rate-1)
}
int main()
{
crimeRate(10)
}That won't compile (you're missing two semicolons), and if it did it would loop infinitely.
Though the site failed to show the usefullness of recursion and so I need someone to explain the usefullness...One example is that of parsing a directory tree structure. If you have a setup like this:
/
file1
file2
dir1/
file3
dir2/
file4
file5
file6
file7
dir3/
file8... the only way to parse it efficiently is to use a recursive function.
boxxertrumps
05-28-2007, 01:59 AM
Like that script you gave me...
http://www.dynamicdrive.com/forums/showpost.php?p=50943&postcount=2
function "paintundersideoffox" is called for the current directory, listing all the files, then when it encounters a directory, paint is called for that directory, and so on and so forth on into infinatum.(assuming thats how many directories you have.)
pcbrainbuster
05-28-2007, 01:15 PM
That won't compile (you're missing two semicolons), and if it did it would loop infinitely.
I usually make the semicolon mistakes on every script, and I do realize that scrit wold go on forever and I can easly edit that to -
void crimeRate(int rate)
{
while (rate!=0)
{
crimeRate(rate-1);
}
}
int main()
{
crimeRate(10);
}
Simple as that...
That'll still loop infinitely. You need to return if rate is less than zero.
pcbrainbuster
05-28-2007, 03:17 PM
Fine, in that case-
void crimeRate(int rate)
{
if (rate!=0)
{
crimeRate(rate-1);
}
}
int main()
{
crimeRate(10);
}
That's more like it. You could also do:
void crimeRate(int rate) {
if(rate <= 0)
return;
crimeRate(rate - 1);
}
pcbrainbuster
05-28-2007, 08:20 PM
Uhhhh, ummm, whats the difference?
Effectively nothing, but it's neater than wrapping the whole body of the function in a massive if block when you have large amounts of code.
mwinter
05-28-2007, 08:42 PM
Along with encryption comes the dangers of it being broken. The government spends a huge amount of money constantly developing new methods of encryption, so don't think you could code something better.
NIST has been releasing industrial-grade encryption algorithms for quite some time. There are usually reference implementations available, and one can probably find improved versions by searching on-line.
At the same time others (and likely the government itself) create complex decryption programs that try to break decryption, so that's out there as well.
Any encryption algorithm worth anything cannot be defeated by another algorithm. However, governments do have access to supercomputers and clusters that could make short work of relatively weak ciphers by brute force.
Another question that pops in my head is that how do programs when clicked on automatically open other programs that ask for a password before it opens?
The first program asks the operating system to start a new process. The first program either does the asking, or the second program does (closing immediately if the check fails).
Also how do certain programs only have one file (itself) and it has songs pictures and all tht being used?
The data is stored within the executable file, just like with a self-extracting archive.
Depends. win32 programs have a WINMAIN function instead.
Windows executables have both a main and a WinMain function. Normally, main is just a stub that would be called when running the program from DOS (not the command line, real DOS) that shows the "This program cannot be run in DOS mode" message and quits. However, that stub can be replaced with code that actually does something useful. When running the program within Windows, the process loader looks for WinMain in preference to main.
As I recall, the setup program on Windows installation CDs exhibit this duality. The DOS version runs the textual system, useful when installing from scratch, whilst the Windows version takes the graphical approach, usually used when upgrading or repairing an existing installation.
Uhhhh, ummm, whats the difference?
It's mainly stylistic: the result is still the same (though at an instruction level, an additional ret op-code may be generated if the compiler doesn't think two is excessive).
pcbrainbuster
05-28-2007, 08:59 PM
The data is stored within the executable file, just like with a self-extracting archive.
How is this done? But I think I know what you mean so the question may be how to do it...
question-
1) How do you add bitmaps/images and sound to a console program?
djr33
05-28-2007, 10:52 PM
In the compilation process, they would simply be embedded.
I say simply in that I'm sure it isn't difficult, just an option in the compiler.
How, specially? No real idea.
But, basically, it's just all written as binary code along with the rest of it and some markers are added so the program knows what bit is what.
pcbrainbuster
05-29-2007, 11:47 AM
I actually now remember this guy asking how to do this... But forgot which forum he asked it at...
How, specially? No real idea.
But, basically, it's just all written as binary code along with the rest of it and some markers are added so the program knows what bit is what.It depends on the executable format, but at least in PE (Windows) and ELF (almost all modern UNIX-like platforms) extraneous data can simply be appended to an executable. The length of important sectors is stored at the top, so anything over that is simply ignored. All that's left to do after that is for the executable part of the program to be able to parse its file to see which bit is which.
pcbrainbuster
05-29-2007, 02:30 PM
...but at least in PE (Windows) and ELF (almost all modern UNIX-like platforms)...
What is PE? I will look it up and someone can explain what it is to me so that I may be confirmed...
edit- I can't find the meaning!
edit- PLease also tell me how to add images and sounds to cnsole programs...
mwinter
05-29-2007, 08:56 PM
How is [resource data added to a program]?
With Windows, there are built-in functions that can be used to edit an executable to insert, remove, or update resources. There are various types of resource, including fonts, icons and string tables. One can also insert user-defined data which can be literally anything.
I don't know exactly how programs such as WinZIP create self-extracting archives, but it's possible that the normal resource system is used, inserting compressed data as an application-defined resource.
1) How do you add bitmaps/images and sound to a console program?
The only images that would be worth including in a console program is the application icon shown in Explorer. The documentation for your development tools will contain instructions for creating resources; the application icon is the usually the first resource.
As for sound, it depends: either interact directly with Windows Multimedia, or use a cross-platform library like OpenAL.
In the compilation process, they would simply be embedded.
I don't remember when resources are usually added, but I'd expect it to occur later in the build process.
It depends on the executable format, but at least in PE (Windows) and ELF (almost all modern UNIX-like platforms) extraneous data can simply be appended to an executable.
I don't think it's that simple for PE (pcbrainbuster: Portable Executable, one of many executable file formats). The PE/COFF specification (http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx) implies that a resource (.rsrc) section would be created. I would have thought that a similar read-only, initialised data section would be used but I did read that section tables don't have to cover the entire file contents.
I would have thought that a similar read-only, initialised data section would be used but I did read that section tables don't have to cover the entire file contents.It probably would, but it's also possible to simply append. I'm sure I tried it at some point.
pcbrainbuster
05-30-2007, 04:45 PM
...that can be used to edit an executable to insert, remove, or update resources. There are various types of resource, including fonts, icons and string tables. One can also insert user-defined data...
I know what resources are, but I really want to know how to do this, does anyone here have a C++ book that may have such info?
...console program is the application icon shown in Explorer. The documentation for your development tools will contain instructions for creating resources; the application icon is the usually the first resource...
I don't plan to use any other library then the standard one for my own twisted particular reason... Plus say your where making a game then your would need images, or if your were introducing yourself, etc... Again please check your books :).
edit- I think I just found out how programs are protected! I think :) - http://www.codeproject.com/system/inject2exe.asp look at the preface section...
edit- By the way you could also use resource hacker to check out all the hundreds of resources used by one program (not always hundred :))...
Thanks.
mwinter
05-30-2007, 10:48 PM
I know what resources are, but I really want to know how to do this,
If you know what resources are, then you should either already know how to add them to an executable, or know where to look for that information. I've already warned you about overestimating the depth of your knowledge.
does anyone here have a C++ book that may have such info?
This has precisely nothing to do with C++. That's why I referred you to the documentation for your development tools.
I don't plan to use any other library then the standard one for my own twisted particular reason...
The only standard C++ libraries are the template (STL) and C run-time libraries, but I doubt you mean either of those.
Plus say your where making a game then your would need images,
C++, as a language, knows nothing of images.
or if your were introducing yourself,
:confused:
pcbrainbuster
05-30-2007, 11:15 PM
If you know what resources are, then you should either already know how to add them to an executable, or know where to look for that information. I've already warned you about overestimating the depth of your knowledge.
By me saying I understand what resources are I was pointing out that I understand what resource are and not how to add them and what not...
This has precisely nothing to do with C++. That's why I referred you to the documentation for your development tools.
OK I see, while I do that someone here maybe able to help me (my compiler is borland's C++ Builder 6 Enterprise Trial)...
The only standard C++ libraries are the template (STL) and C run-time libraries, but I doubt you mean either of those.
I don't know what I am talking about, but I mean I will only use the standard C++ items such as libraries etc...
C++, as a language, knows nothing of images.
I don't understand what you mean... But just recently I came across a console program with Images and sound but don't remember where I downloaded it from...
:confused:
I mean that if you wanted to introduce yourself through a program you will be using both text and image(s)...
other -
1) You seem to be slowing down on your posts, what happend?
2) I just learnt that you can create popup windows which can contain images, sound, buttons etc through the console, is this true? And if so then would this require me to learn win32 programming?
edit- Check this out! A free win32 API book which gives info on resources but I am lost :p typical, http://www.rohitab.com/discuss/index.php?act=attach&type=post&id=698 look for using resources in the menu...
mwinter
05-31-2007, 08:54 PM
I don't know what I am talking about, but I mean I will only use the standard C++ items such as libraries etc...
I still have no idea what you're trying to say.
C++, as a language, knows nothing of images.
I don't understand what you mean...
You wrote:
Plus say [you were] making a game then [you] would need images ... Again please check your books
None of this - images, sounds, etc. - has anything to do with C++. Stop trying to do something "cool": you barely know the language, let alone how to do something useful with it.
1) You seem to be slowing down on your posts, what happend?
I do have a life outside this forum, and I do like spending some of my free time selfishly.
2) I just learnt that you can create popup windows which can contain images, sound, buttons etc through the console, is this true?
If a program is built to run in a graphical environment (such as Windows), then of course it can create graphical elements.
At least in Windows, a console program is simply software that causes the OS to create a console. GUI-based programs are essentially the same thing, minus the console.
And if so then would this require me to learn win32 programming?
You would need to understand the Win32 API if you were going to use it, yes. However, you'd also need to know more about writing software, too.
pcbrainbuster
06-06-2007, 09:07 PM
Quote:
I still have no idea what you're trying to say.
Well don't worry this line isn't going anywhere anyway .
Quote:
None of this - images, sounds, etc. - has anything to do with C++. Stop trying to do something "cool": you barely know the language, let alone how to do something useful with it.
I wasn't trying to do anything cool, I don't really have anyone to impress. I just wanted to know how to add images and sound using C++... For example IE is probably mostly C and yet using scripts and what not you can add images, sound and animation. And C++ is basically C but with improvements and you should be able to see why I keep asking the same question...
Quote:
I do have a life outside this forum, and I do like spending some of my free time selfishly.
How could you! .
Quote:
If a program is built to run in a graphical environment (such as Windows), then of course it can create graphical elements.
At least in Windows, a console program is simply software that causes the OS to create a console. GUI-based programs are essentially the same thing, minus the console.
You do realize I was talking about the console itself in a graphical environment all this time right?
question -
1) What is a *.net language?
2) Is Windows Live Messenger completely C? I am asking this because I like its features such as 'remote desktop' and 'live message sending' and would one day like to do the same thing in a different way...
tech_support
06-08-2007, 09:03 AM
1) What is a *.net language?
http://www.google.com/search?q=dot+net
2) Is Windows Live Messenger completely C? I am asking this because I like its features such as 'remote desktop' and 'live message sending' and would one day like to do the same thing in a different way...
I think so.
Where did you find "Remote Desktop"? I can't find it anywhere.
pcbrainbuster
06-08-2007, 03:05 PM
http://www.google.com/search?q=dot+net
I'll try...
I think so.
Where did you find "Remote Desktop"? I can't find it anywhere.
Well actually I was refering to the thing in the action menu called request remote help, it basically gives you control over the requesting user's computer (though he/she gets to decide whether you can just look or take 100% control...) but this feature is only available when your actually taking to someone...
tech_support
06-10-2007, 08:50 AM
Ahh... http://www.uvnc.com/
pcbrainbuster
06-10-2007, 02:10 PM
Thanks for that post, I actually am gonna download and test it out...
pcbrainbuster
06-13-2007, 08:01 PM
I'm just wondering here and just say yes or no, does anyone mind being my C++ tutor through Windows Live Messenger? And please do not saying anything other then yes or no and don't even ask why...
Thanks.
djr33
06-13-2007, 08:20 PM
No.
(:p)
pcbrainbuster
06-13-2007, 08:22 PM
Grrrrrr!
:p
Y'know, technically speaking he didn't ask if you would be his tutor, he asked if you would mind being his tutor. As such, you just said that you wouldn't mind: i.e. that you're happy to do it.
djr33
06-13-2007, 10:28 PM
Oops.
Yes.
And a question... does this mean that aside from yes/no, there will be no more replies to this thread? ...it IS 18 pages already....
tech_support
06-14-2007, 03:07 AM
Google's a good tutor.
Just look him/her/it up.
24/7 access... No shouting... No sick-leaves :D
pcbrainbuster
06-14-2007, 07:04 PM
Yeah but your just not seeing the point... Google is good but in the end there is always something that the author will miss out...
And by the way Twey: nice speech :p...
mwinter
06-16-2007, 06:23 PM
I just wanted to know how to add images and sound using C++...
From what I recall of this thread (I'm not going to re-read it), you've been told repeatedly.
For example IE is probably mostly C and yet using scripts and what not you can add images, sound and animation.
Yes, by calling predefined code that renders these things. In the case of IE, it'll use the Win32 API. However, other interfaces can be used instead (such as wxWidgets and Qt, which have been mentioned numerous times).
And C++ is basically C but with improvements
No, it isn't. C++ is largely, but not totally backwards-compatible with C, but that's all that should be said on the subject.
and you should be able to see why I keep asking the same question...
And, frankly, I'm tired of answering it.
If a program is built to run in a graphical environment (such as Windows), then of course it can create graphical elements.
At least in Windows, a console program is simply software that causes the OS to create a console. GUI-based programs are essentially the same thing, minus the console.
You do realize I was talking about the console itself in a graphical environment all this time right?
Yes, your point? You shouldn't be looking at interacting with the graphical subsystem yet. Learn the language, first.
2) Is Windows Live Messenger completely C?
I would have expected it to use a .NET language.
I am asking this because I like its features such as 'remote desktop' and 'live message sending' and would one day like to do the same thing in a different way...
This has nothing to do with the language used to write the software.
pcbrainbuster
06-16-2007, 10:13 PM
Well I'm sorry for my troubles but please try to bare with me, understand that I am a 13 year old who walks around with a undeveloped brain, ie zombie :p...
edit - What is wrong with my test? -
#include <iostream>
using namespace std;
class multiplicate
{
public :
int x, y, z;
multiplicate(int num)
{
x=num*10;
y=num*100;
z=num*1000;
}
~multiplicate() {}
}
int main()
{
int contin=1;
int number=0;
while(contin!=0)
{
cout << "Write down a number that will be multiplicated by 10, 100 and 1000 times respectively - ";
cin >> number;
cout << "\n\n";
multiplicate act(number);
cout << "\n\nDo you want to start again? 1 for yes and 0 for no -";
cin >> contin;
}
return 0;
}
Thanks.
mwinter
06-17-2007, 10:30 PM
edit - What is wrong with my test? -
When asking for help debugging, always state what you expect to happen, as well as what you observe (or don't). If we don't know what code is meant to do, we cannot tell you why it's not doing it!
class multiplicate
{
public :
int x, y, z;
Classes should exhibit encapsulation: data members should not be public. Whilst this isn't a rule, public members should be considered exceptional.
multiplicate(int num)
If a variable can be reasonably declared const, do so. Not only can it help serve as documentation (such a variable is clearly not meant to change) and aid in debugging (a compiler will issue a diagnostic if an attempt is made to change a constant), but certainly with references, if an argument isn't declared constant, constant values cannot be passed even though no attempt will be made to change them.
Going back to the template example I gave earlier in the thread, for instance, provides a demonstration:
template <typename T>
const T& min(const T& a, const T& b) {
return (a < b) ? a : b;
}
If all of the const keywords were removed and one were to pass constants as arguments, the program wouldn't compile. As it is, the function will accept both constant and mutable arguments.
~multiplicate() {}
There's not much point in defining a destructor if it doesn't do anything (virtual destructors, aside).
tech_support
06-18-2007, 01:29 AM
Yeah but your just not seeing the point... Google is good but in the end there is always something that the author will miss out...
That's why they're SEVERAL pages of results, meaning SEVERAL authors.
djr33
06-18-2007, 09:51 PM
and when searching for such general/basic questions, there will likely be many more than just several pages.
mburt
06-19-2007, 07:01 PM
My suggestion: drop C++, it's incredibly tough to learn the way you're trying to.
Python, with the wxPython widget is absolutely incredible.
This is an "image" script for a wxPython script which works on all platforms.
import wx
class Image(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, id, title)
bmp = wx.Image("image.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
wx.StaticBitmap(self, -1, bmp, (5,5))
class Run(wx.App):
def OnInit(self):
dlg = Image(None, -1, "Image Script")
dlg.ShowModal()
dlg.Destroy()
return True
app = Run()
app.MainLoop()
You'll need Python:
http://www.python.org/
and wxPython:
http://www.wxpython.org/
mburt
06-19-2007, 07:21 PM
Screen Capture:
http://i14.tinypic.com/54bt3d2.png
pcbrainbuster
06-19-2007, 08:25 PM
I've done to much toquit now really, but since the last time I actually talked about anything I have learnt a few more things - classes (finally), constructors and destructors. But only the basics...
I'm gonna try and golearn what these things called templates are...
edit - I just realized that I do not need to learn tmplates yet and am finding something else to look up. I think I remember somthing about up-casting by mwinter and now will look it up...
edit - Again omething which I should learn later. I think I should build up my knowlegde of classes more...
mwinter
07-03-2007, 08:11 PM
I think I remember somthing about up-casting by mwinter and now will look it up...
When I mentioned up-casting, the concept that I was actually considering was down-casting. Up-casting is safe, down-casting is not.
pcbrainbuster
07-03-2007, 08:15 PM
Well I'm too confused for that :p I havn't quite learned anything about up/down-casting...
If we have two classes (let's be imaginative and call them ObjectA and ObjectB), where ObjectB is a subclass of ObjectA:
class ObjectA {
public:
ObjectA() {};
~ObjectA() {};
void foo() {};
};
class ObjectB : public ObjectA {
public:
ObjectB() : ObjectA() {};
void bar() {};
};It's entirely safe to (up-)cast from ObjectB to ObjectA, since an ObjectB instance will always have all the properties and methods of an ObjectA. ObjectB must have a foo() method; if it doesn't implement its own version it will get ObjectA's default implementation:
ObjectB *oB = new ObjectB;
ObjectA *oA;
oA = static_cast<ObjectA*>(oB);
oA->foo(); // always fine
However, there is no such guarantee when going (down-casting) the other way: an ObjectA need not implement everything that an ObjectB does, and indeed, in our sample ObjectA lacks ObjectB's bar() method:
ObjectB *oA = new ObjectA;
ObjectB *oB;
oB = static_cast<ObjectB*>(oA);
oB->bar(); // fails!
pcbrainbuster
07-04-2007, 07:26 PM
Thanks for you post Twey but unluckly I havn't even learnt subclasses, all this time I've been getting used to classes(basics). Do you mind quickly filling me up on all the info of subclasses?
djr33
07-04-2007, 07:40 PM
"all the info"?
...do you not look at tutorials?
I have no idea how to use subclasses. But if I wanted to, I'm sure there's plenty of info on how to start on google or in any tutorial.
pcbrainbuster
07-04-2007, 07:49 PM
What dont you understand about what I have already written! I have clearly stated that nearly all the tutorials I do look for end up using some long complicated words...
Basically I understand what Twey tries to point out(well most of the time :)) compared to, well, other sites...
edit - I realizethat this is abit random but does anyone mind explainng bits to me?
tech_support
07-06-2007, 05:55 AM
Then look up the long and complicated words...
Or learn an easier language.
pcbrainbuster
07-06-2007, 09:51 PM
Exactly HTML, JavaScript and all those others were guinny pigs...
I think perhaps tech_support meant easier than English :p
pcbrainbuster
07-07-2007, 10:20 PM
Oh shoot, sorry tech_support that was way out of line and I apologise :(
edit - By the way guys I actually tried and read and understood everything the was at main level of importancy on this page - http://www.cplusplus.com/doc/tutorial/classes.html - Up to Constructors and Destructors...
tech_support
07-08-2007, 01:09 AM
Oh that... Nevermind. I can shoot you later ;)
I'm sure you meant no harm.
edit - By the way guys I actually tried and read and understood everything the was at main level of importancy on this page - http://www.cplusplus.com/doc/tutorial/classes.html - Up to Constructors and Destructors...There's nothing scary about constructors and destructors. A constructor is just a special method that's called when the class is created, and a destructor is one that's called when the class is destroyed.
pcbrainbuster
07-09-2007, 06:46 AM
Oh that... Nevermind. I can shoot you later
I'm sure you meant no harm.
Well I'm sure you do :p
And Twey I was simply trying to point out that I read upto it, and I already understand the basics...
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.