Need help with simple code. Very new to C++

This is a discussion on Need help with simple code. Very new to C++ within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by PersianStyle well I tried to put return; just to see and it compiled But I just dont ...

  1. #16
    C++11 User Tux0r's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    135
    Quote Originally Posted by PersianStyle View Post
    well I tried to put return; just to see and it compiled
    But I just dont put a return statement at all and remove the line completely.
    Is this correct?
    In a void function you don't have to have a return; if you don't want to. But it can be used to skip out of the function earlier than at the end.


    Code:
    void render(const Model& model) {
        if(model.invisible())
            return;
    
        model.render();
    }

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    Main returning void is no standard C++, so it's not guaranteed to compile (it should never compile, really).
    But, PersianStyle, you really lack the very basics of the language. I suggest you get a good book and read it through before you do anything else. I recommend Accelerated C++. There are more good books in the books thread.
    Believe me, it will help you a lot to read it before doing anything else.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Jul 2009
    Posts
    20
    Quote Originally Posted by Elysia View Post
    Main returning void is no standard C++, so it's not guaranteed to compile (it should never compile, really).
    But, PersianStyle, you really lack the very basics of the language. I suggest you get a good book and read it through before you do anything else. I recommend Accelerated C++. There are more good books in the books thread.
    Believe me, it will help you a lot to read it before doing anything else.
    No thanks, I hate reading books LoL
    I been learning a lot better this way.

  4. #19
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    You can give up becoming any decent programmer if you don't read any books, because the code you write is so flawed and your understanding so bad that everyone will have to explain everything you do to you.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    I just started programming as well persian... and I have asked alot of dumb questions too. Don't let it get you down. Try using the Lessons page on the main web site for this board, or find an easier to navigate tutorial page. So when you ask yourself how do I declare a function. You look on the page click on the tab that says functions and walaa. You can usually find your answer on the net quicker than someone gives it. I don't read an entire book and then program that would be boring. I learn one new idea/concept from a book or tutorial and then devise a new program to utilize it. Try to stay within your boundries of knowledge and then repitition gets it in your head. If you would like you can email me at haloismyvice@hotmail.com and I would be happy to help you with questions, but remember part of being a good programmer is being to good problem solver don't look for the answer to fast or you are shortcutting building your problem solving skills.

    No matter what anyone says a human being will succeed at what he/she wants through persistant and consistent effort. Henry Ford did not know how to do half the stuff his company did it was surrounding himself with more knowledgable people that got him there.

  6. #21
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    You may do it the way you want, naturally.
    However, books do have advantages. You read a chapter in a book, do the exercises, move on.
    When you finish the book, you have a solid understanding of at least the basics. And I mean such things as functions, loops, variables, stuff that is absolutely essential for any program. Making a program without them just isn't possible.
    And since it seems the OP doesn't even grasp functions, she/he does indeed need to learn the basics, and books are great for that. Tutorials often cover just a small spectrum of things and many tutorials are just plain wrong.

    After having read a book, or while reading a book, that is the time for questions. All the while, you can put your knowledge to use. But not before. And not before knowing the absolute basics.
    Say what you will about that. That's the cold hard truth.

    I'll add two more things, as well.
    Firstly, the forum is more about answering questions than teaching. Most members will simply refer you to books or tutorials if you don't know how, for examples, templates work.
    Secondly, it would be frustrating if you run into a dead end in your programming because you don't know how to solve it and find out that if you simply had learned sufficient basics of the language before attempting to write the program, you could easily have solved it.
    Last edited by Elysia; 07-13-2009 at 02:26 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 11-23-2005, 07:53 AM
  2. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Windows Programming
    Replies: 0
    Last Post: 10-14-2002, 01:29 PM
  3. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 11:51 AM
  4. Simple Code, looking for input.
    By Alien_Freak in forum C Programming
    Replies: 3
    Last Post: 03-03-2002, 10:34 AM

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