bad code?

Started by
14 comments, last by death_jester 22 years, 3 months ago
quote:Original post by BioSquirrel
It''s not "int main()". It should be like this:

void main()

Declaring main with a return type of void is illegal as of the C and C++ standards. Shame on you!



Once there was a time when all people believed in God and the church ruled. This time is called the Dark Ages.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Advertisement
Uhhhhhhh no....?
Uh, yes. Love it or hate it, that''s what the standard says.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Hmmm...that''s odd. I remember reading a TON of C++ tutorials that said "void main()"...although those tutorials might not have complied with the standard.

-----------------------------
"C++ isn''''t hard, you fool!"
Famous Last Words
-----------------------------
Justin O'ConnerProducer, Designer, ProgrammerUnseen Studios
Bark( ) needs a return type.
dude, almost everything about it is wrong.
    //----------- main.cpp ---------------//#include "dog.h"#include <iostream.h>int main(void){   CDog myDog;   cout<<myDog.Bark()<<endl;   return 0;}//----------- dog.h ------------------//#ifndef _DOG_H#define _DOG_H#ifndef _STRING_H#include <string.h>#endifclass CDog{   public:      string Bark(void);      unsigned int GetAge(void);      unsigned int GetWeight(void);   private:      unsigned int UIage,UIweight;};#endif//-------------- dog.cpp -------------//#ifndef _DOG_H#include "dog.h"#endif#ifndef _STRING_H#include <string.h>#endifCDog::CDog(void){   UIAge=5;   UIWeight=30;}inline string CDog::Bark(void){   return "Woof!";}inline unsigned int CDog::GetAge(void){   return UIAge;}inline unsigned int CDog::GetWeight(void){   return UIWeight;}    

you missed all the naming conventions and your code was implying that your header would include possibly non-portable code (the input/ouptut system). iostream.h is very portable, but what if he was using some other system? Heck, I've probably missed some naming conventions, that was all I could remember off the top of my head.

One tip, never include a file that you don't need. This is a major code file size optimization.

Edited by - capn_midnight on January 12, 2002 8:54:16 PM

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

This topic is closed to new replies.

Advertisement