Thread: New To C++...

  1. #1
    Registered User
    Join Date
    Sep 2003

    New To C++...

    I am a bit new to C++ and I have a few questions...

    1)What are the differences between variables, pointers, and references and how do you know which one to use?

    2) How do I know which variable type to use:
    unsigned short int
    short int
    unsigned long int
    long int
    unsigned int

    3) when creating an application I use the app wizard but for some reason I don't see the application window. How do I open the application window so I can add controls to is.

    4) in the app wizard there is a section to chose the base class, How do I know what the base class I should use for the application.

    I have three C++ books but none of these questions seem to be answered in them so if someone could please answer these questions... Thank You

  2. #2
    Registered User
    Join Date
    Mar 2002
    1) variables are holders of information. pointers and references both relate to a variable, can't have (a valid) one without the other). references are essentially pointers with all the dirty work being done behind the curtain. pointers and references come in handy when you want to pass large objects from one function to another. They both allow you to change values of a variable back in some other function, since you can only have one return value per function. pointers allow you to declare items on the free store using dynamic memory.

    You learn how to use them all as you start writing your own programs.

    2) see the last line to answer 1.

    3 and 4) are both compiler specific. Not knowing which compiler, can't help. However, for now can probably forget about base classes. They have to do with inheritance, etc., and that's a ways down the road.

  3. #3
    Registered User axon's Avatar
    Join Date
    Feb 2003
    I find it highly unlikely that a single answer to your question cannot be found in any of your 3 books. No matter how bad the book, things like that are bound to be in there. On these facts alone I conclude that you are a lazy liar who doesn't want to do his own homework.

    If the books intimidate you too much to actually open them once in a while, try here


    some entropy with that sink?

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  4. #4
    Join Date
    Sep 2003
    I think such things aren't just explained in books because books teach you the use of the language stuffs but won't tell you when to use it, I think that it is somehow obvious that we use what suits us the most in the present case... Because as you will see, there are many cases where you can use different features of the language to solve the problem, it will depends on either your coding style or your specific needs.
    Besides, trying to start learning pointers when not being able to understand well native primary types is no good. If you want, you can learn about references without trying to understand how it "really" work.
    Also, you shouldn't be using the wizard, forget about it for now.

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    If your books don't clearly cover variables / pointers / references. They are not good beginning C++ books!
    Here's a list of books. My beginning book was Teach Yourself C++ in 21 Days by Jesse Liberty. It has the answers to your questions 1 & 2. This book is structured for self-learning with questions & exercises at the end of each chapter ("day"), with answers & solutions in the back. It is clearly written and easy to understand... And it makes a handy (but incomplete) reference book.

    1) A very common use of pointers is with character arrays (C-style strings). You pass a pointer into your function. Your function can't return the modified string... it returns the pointer.

    2) You can use sizeof() to get the capacity of each of the variable types on your system. You can also use the <limits> header file which contains constants like INT_MIN & INT_MAX. The standard specifies a minimum capacity for each type.
    You wll have to determine when you need a float or a signed variable. Oh, the standard library functions may require you to use a particular type too.

    3 & 4) Don't use the wizard! It's going to throw stuff into your program that you don't understand, and stuff that you don't want or need. And, it will take-away some of your learning experience by writing code for you. I'll bet that 90% of programmers don't use wizards, although they probably use an "empty-shell" program that they wrote themselves.

    If you want to learn how to use your wizard, you will have to find the info in your compiler's documentation, or get a book that is specific to that particular compiler.
    Last edited by DougDbug; 09-24-2003 at 02:26 PM.

Popular pages Recent additions subscribe to a feed