• Basic C++ programming help
    7 replies, posted
Hello, I'm getting this error 24 F:\ULTIMATE EXAMPLE PROGRAM.cpp new types may not be defined in a return type 24 F:\ULTIMATE EXAMPLE PROGRAM.cpp extraneous `int' ignored 24 F:\ULTIMATE EXAMPLE PROGRAM.cpp new types may not be defined in a return type even when I return 0 and i don't know why. I'm using dev C++ #include <iostream> #include <limits> //include for press enter to exit using namespace std; class Box //creates class { public: // do I even have to say it? double hi; // creates a duobble variable, name variable hi void setsup(int x) { sup = x; } int getsup() { return sup; } private: //really, it's self explanatory int sup; } int main() //int main is need for every porgram, put as litlle as possible in there { Box Box1; //declares an object, Box1 Box1.hi = 4; //to name a variable in another class put object.classvar Box1.setsup(5); cout << Box1.hi << "\n"; // prints var or character if "" and \n makes new line cout << Box1.getsup() << "\n"; //ending of program starts here cout << "PRESS ENTER TO EXIT"; cin.ignore( numeric_limits<streamsize>::max(), '\n' ); //when press enter exits return 0; }
Use code tags please
[QUOTE=Meatpuppet;40906428]Use code tags please[/QUOTE] Sorry [code]#include <iostream> #include <limits> //include for press enter to exit using namespace std; class Box //creates class { public: // do I even have to say it? double hi; // creates a duobble variable, name variable hi void setsup(int x) { sup = x; } int getsup() { return sup; } private: //really, it's self explanatory int sup; } int main() //int main is need for every porgram, put as litlle as possible in there { Box Box1; //declares an object, Box1 Box1.hi = 4; //to name a variable in another class put object.classvar Box1.setsup(5); cout << Box1.hi << "\n"; // prints var or character if "" and \n makes new line cout << Box1.getsup() << "\n"; //ending of program starts here cout << "PRESS ENTER TO EXIT"; cin.ignore( numeric_limits<streamsize>::max(), '\n' ); //when press enter exits return 0; }[/code]
[code]class Box { public: double hi; void setsup(int x){ sup = x; } int getsup(){ return sup; } private: int sup; }; [/code] Semicollon at the end.
Also you probably want to define sup before using it in functions. So the private section should be at the top before the public section.
Why?
[QUOTE=flayne;40965838]Also you probably want to define sup before using it in functions. So the private section should be at the top before the public section.[/QUOTE] Matter of preference. I like to have members before methods, but that doesn't mean it [i]should[/i] be this way.
[QUOTE=Dienes;40973294]Matter of preference. I like to have members before methods, but that doesn't mean it [i]should[/i] be this way.[/QUOTE] Fair enough. I just think it looks more readable if you define things before you use them in general. But, yes I suppose that is just my preference.
Sorry, you need to Log In to post a reply to this thread.