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();
}
Printable View
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.
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.
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 [email protected] 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.
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.