I mean I was asking myself whether I could create classes like for example...
Instead of having to declare a limited number of classes and declare them specifically with names in the code, the user could say, I would like to create a class and I would like it to have this name... Something like this pseudocode...
Program asks if the user wants to create a class.
User confirms.
The program asks about the name of the class.
The program creates name.class.
Also, is there anyway to create a number of classes with a for cycle? I mean I was trying to do an exercise with student files. So my idea is for example...
The program asks the user how many files do you want to create and it creates the same amount of classes and after that the user could edit a specific class by inputting its number or name. The one thing I'm almost sure won't work is classes named with numbers only.
Classes in C++ are AL declared and defined at compile time.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!) 2008, 2009 In theory, there is no difference between theory and paractice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
What do you mean with 'create' ? Allocate memory for a existing class ? Simply create it on the heap with the 'new' command. Or do you mean actually create a new, non-existing class out of nothing ?
Last edited by Skizmo; January 7th, 2009 at 12:45 PM.
The reason why this is a strange question is because the name of an object isn't terribly relevant at runtime; it's merely a way to refer to it in the code. Once the code is compiled the name becomes irrelevant.
However, you might be able to do what you want using a std::map<std::string, Number>.
rather than ask the user to name the class with a string for example:
string name;
Number name;
This kind of declaration generates error C2371.
I kindly suggest you, please follow TheCPUWizard's advices. When you will understand C++ languages and you will practices it, you will find yourself the answer of many questions like this.
So, technically the first thing I am asking is impossible to do in C++?
Which is EXACTLY why you need to....
1) Get a GOOD Book (the kind that is printed on PAPER)
2) Read every word, starting at page 1
3) Type in EVERY piece of code (even if there is a CD/DVD/Download - manually type it in)
4) Step through every line of code with the debugger (yes, even the "hello world" sample.
5) Do not move to the next chapter/section until you are 100% confident you understand EVERYTHING in the current chapter (slap yourself if you ever think "I dont need to know this specific aspect").
Ad-hoc learning does NOT work for C++. It is the (probably) most detail oriented of all of the computer programming languages. A small gap in fundamental knowledge can quickly lead to fatal flaws that are virtually impossible to later overcome.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!) 2008, 2009 In theory, there is no difference between theory and paractice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
1) Get a GOOD Book (the kind that is printed on PAPER)
Would you suggest me a good one? I'm reading Deitel's How to program in C++, I don't know if it's really good, but sometimes I feel the topics aren't ordered very well. Anyway, I'm still a beginner, so I would accept the professionals' advice.
Would you suggest me a good one? I'm reading Deitel's How to program in C++, I don't know if it's really good, but sometimes I feel the topics aren't ordered very well. Anyway, I'm still a beginner, so I would accept the professionals' advice.
The first thing I would suggest is a search here on CodeGuru, this topic has been discussed many time.
I am always hesitant to recommend books in general. There are two criteria a book must meet to be "good":
1) It must be accurate and current.
2) It must be written in a style that is appropriate for the reader.
As an example, I just LOVE the Scott Meyers books (they are more advanced that you are right now). I find them very enjoyable to read, with "funny" one-liners and sometimes very scarcastic comments. Other people find that distracting, and prefer a "dryer" style.
After you do the search that I recommend (and many of the senior people here have posted good reasons NOT to use specific books - I say do not use anything published before 2004), then (if at all possible) go to a bookstore and spend a couple of hours reading the first part of each book that made the "recommend list". See which one is best suited to YOUR style of learning.
This is the ONE place where a person doing independant study has a real opportunity that students in a formal classroom do not. They (almost always) MUST use the textbook that the teacher/professor dictates.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!) 2008, 2009 In theory, there is no difference between theory and paractice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
I am still a little concerned that the material really is too accelerated for a rank beginner, but other than that the book I would recommend to you is Accelerated C++: Practical Programming by Example by Andrew Koenig and Barbara E. Moo.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
Well, actually, that's my problem, I'm a student and they tell us to use the Deitel book, maybe because the university has some contract with the editorial, I don't know, but anyway, thanks for the advice, I'll see where to start from.
NOTE: The following post contains a personal bias....
One book to consider is "SAMS Teach Yourself C++ in 21 Day" or the newer "SAMS Teach Yourself C++ in an Hour a Day".
While I have a disagreement with the time scale, I am of the opinion that that the written material is quite readable, well organized, and covers the most important topics in learning C++.
I can also stand behind the 5th and 6th editions of "SAMS Teach Yourself C++ in 21 Day" in terms of confiormance of the code samples with the ISO specification since I was the Technical Editor (ooops...now anwone can have a 50% chance of knowing my real name ) responsible for ISO compliance testing.
I also know the Authors, which adds to the personal (positive) bias.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!) 2008, 2009 In theory, there is no difference between theory and paractice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Bookmarks