Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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?

  • Administrators
Posted
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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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.

  • *Experts*
Posted

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

"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
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...