sjn78 Posted March 13, 2004 Posted March 13, 2004 I'm taking a C++ subject for uni and have a couple of questions if anyone canhelp me out. Don't worry, its not an assignment question!! I don't have any troubles with the syntax. What's the purpose of makefile's. Does it clean up your source code that you have lying around and produce a better exe or am I talking dribble? I would ask the lecturer, but I am studying by correspondence and it makes it hard to ask questions. I must say, I have never actually 'learnt' about classes before and just 2 weeks into the subject, I have learnt so much about them and how they are used. Can't wait until I get back into .NET to try using this stuff properly. Quote
Administrators PlausiblyDamp Posted March 13, 2004 Administrators Posted March 13, 2004 makefiles just automate a build process, they usually dictate the order files and projects get built. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
sjn78 Posted March 13, 2004 Author Posted March 13, 2004 Well I was way off. lol I have also noticed the exe's built are huge. I have a small main procedure and then a separate .h file that I use which is only a screen full of code, but when compiled it is nealry .5mb Whats the deal with that? Quote
Administrators PlausiblyDamp Posted March 13, 2004 Administrators Posted March 13, 2004 Debug builds are often much larger than release builds (no debug stuff plus code optimisation takes place). Also most C++ code will involve linking to various runtime libraries - will makea big difference if you link to the dll version or the static version. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
sjn78 Posted March 13, 2004 Author Posted March 13, 2004 OK thanks. I have a pratice exercise that is not working. Its just to make a class and well, you will probably understand when you see it. The problem is I cant get the getCount() to work. I think it is returning the address of the variable not the value. It is suppose to be an int that keeps count of how many objects have been created. I have tried several diffferent things but nothing is working. #include <iostream> #include <string> using namespace std; class Tool { public: Tool(const string& t); const string& name() const; // Gets ToolName const int getCount() const; // Gets ToolCount private: string toolName; int toolCount; }; // Tool constructor Tool::Tool(const string& t) { toolName = t; toolCount ++; } // Retrieve Tool Name const string& Tool :: name() const { return toolName;//.c_str(); } // Retrieve Tool Count const int Tool :: getCount() const{ return toolCount; } int main() { //Testing the class Tool t1("hammer"); cout << "Tool Name - " << t1.name() << endl; cout << "Tool Count - " << t1.getCount() << endl; Tool t2("spade"); cout << "Tool Name - " << t2.name() << endl; cout << "Tool Count - " << t2.getCount() << endl; Tool t3("rake"); cout << "Tool Name - " << t3.name() << endl; cout << "Tool Count - " << t3.getCount() << endl; } If anyone can have a look and see what is going on, I would be very grateful for your help. Quote
*Experts* Nerseus Posted March 13, 2004 *Experts* Posted March 13, 2004 I wouldn't imagine you'd want either of the "const" keywords on your definition of getCount. Just make it: int Tool::getCount() { return toolCount; } -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
sjn78 Posted March 13, 2004 Author Posted March 13, 2004 I tried that firstly and this is my output: Tool Name - hammer Tool Count - 1 Tool Name - spade Tool Count - 863866 Tool Name - rake Tool Count - 794197 Thanks again Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.