Forum: C++ Aug 7th, 2009 |
| Replies: 7 Views: 363 |
Forum: C++ Aug 7th, 2009 |
| Replies: 7 Views: 363 You overload an operator when it makes sense to do so.
Say that you create a custom string class MyString.
It makes sense to overload the + operator, but not the ~. |
Forum: C++ Feb 8th, 2009 |
| Replies: 12 Views: 631 Call the copy constructor.
Let me explain:
Shoe shoe1; // calls the constructor
Shoe shoe_copy(shoe1); // copy constructor
Shoe shoe_copy = shoe1; // copy constructor, even if it seems it's... |
Forum: C++ Feb 8th, 2009 |
| Replies: 12 Views: 631 shoe_copy=shoe1; will call the assignment operator, not the copy constructor. The copy constructor is called for example when you pass an object to a function by value.
// copy constructor called... |
Forum: C++ Feb 7th, 2009 |
| Replies: 7 Views: 1,063 You can do that:
bool checkUnsignedInt(const string &str)
{
return atoi(str.c_str()) >= 0;
} |
Forum: C++ Jan 10th, 2009 |
| Replies: 4 Views: 299 One thing about collisions. At the moment I'm using functions that take 2 arguments. Would it be better if each object had a collision function so I could say:
Sprite s;... |
Forum: C++ Jan 10th, 2009 |
| Replies: 5 Views: 369 Why do this? Is cin hard to remember? You need to get used it, you'll see it everywhere!! Think of it as "console input", this might help you remember. When I started C++ I was forgetting everything... |
Forum: C++ Jan 10th, 2009 |
| Replies: 4 Views: 299 Well my main() function has become a mess... What should I do next time to prevent this?
int main(int argc, char *args[])
{
srand((unsigned)time(0));
if(!init())
return 1; |
Forum: C++ Dec 7th, 2008 |
| Replies: 8 Views: 1,035 Try darkGDK, it's free and very easy to use. Google it. |
Forum: C++ Dec 7th, 2008 |
| Replies: 3 Views: 475 |
Forum: C++ Dec 6th, 2008 |
| Replies: 3 Views: 475 #ifndef DARK_OBJECT_H
#define DARK_OBJECT_H
#include "DarkGDK.h"
namespace DarkObject
{
class Object // abstract
{
public: |
Forum: C++ Nov 27th, 2008 |
| Replies: 3 Views: 2,274 void increment(const Machine &aMachine, int amount = 1)
{
rackID = rackID - amount;
}
1. You are... |
Forum: C++ Nov 25th, 2008 |
| Replies: 7 Views: 438 |
Forum: C++ Nov 25th, 2008 |
| Replies: 8 Views: 1,949 result is a local variable, which is destroyed when the functions ends. So a garbage value is destroyed. The best solution is to do what is said by the poster above.
If you need to work with... |
Forum: C++ Nov 25th, 2008 |
| Replies: 7 Views: 438 This is just used to show how it's done :) |
Forum: C++ Nov 25th, 2008 |
| Replies: 7 Views: 438 Why?
------------
@StuXYZ
Yes it does, thanks a lot. I'm not trying to do anything, just to understand :D |
Forum: C++ Nov 25th, 2008 |
| Replies: 7 Views: 438 Hi, I'm studying operator overloading through C++ the complete referece and I've got some questions.
In the book, the author writes this:
loc loc::operator++()
{
++longitude;
++latitute; |
Forum: C++ Nov 25th, 2008 |
| Replies: 7 Views: 842 Read this:
http://www.daniweb.com/forums/announcement8-3.html |
Forum: C++ Nov 21st, 2008 |
| Replies: 1 Views: 344 Just a bit of advice. No one is going to download all these files. You should provide the code with the errors and try to explain. Help us to help you. |
Forum: C++ Nov 17th, 2008 |
| Replies: 3 Views: 343 Try adding header guards in header.h
#ifndef HEADER_H
#define HEADER_H
#include <iostream> // put your includes in the header file so you don't need to include them in every file that uses... |
Forum: C++ Nov 17th, 2008 |
| Replies: 5 Views: 935 Exactly. It's the assignment operator in PASCAL and used in pseudocode as well. |
Forum: C++ Nov 17th, 2008 |
| Replies: 5 Views: 935 Why don't you write this program and see the results? |
Forum: C++ Nov 17th, 2008 |
| Replies: 20 Views: 1,040 Do you have to make the class? |
Forum: C++ Nov 17th, 2008 |
| Replies: 24 Views: 65,641 |
Forum: C++ Nov 17th, 2008 |
| Replies: 20 Views: 1,040 Ok.Isn't it an object? (a class) |
Forum: C++ Nov 17th, 2008 |
| Replies: 20 Views: 1,040 |
Forum: C++ Nov 17th, 2008 |
| Replies: 23 Views: 1,460 So your book isn't good.
If you have money and can buy online I recommend Beginning C++ Game programming (http://www.amazon.com/Beginning-C-Game-Programming-Development/dp/1592002056) (it's not... |
Forum: C++ Nov 17th, 2008 |
| Replies: 20 Views: 1,040 Show us the definition of the "list". |
Forum: C++ Nov 17th, 2008 |
| Replies: 23 Views: 1,460 Do you have any book that you learn from?
edit:
the way you did it, it will ask only once for the answer and the program will terminate. In my version it will keep asking until you enter the... |
Forum: C++ Nov 17th, 2008 |
| Replies: 23 Views: 1,460 #include <iostream>
#include <cstdlib>
#include <iomanip>
#include <ctime>
using namespace std;
int main()
{
srand((unsigned)time(0));
int random_integer1 = 1 + rand() % 500; |
Forum: C++ Nov 17th, 2008 |
| Replies: 4 Views: 1,055 |
Forum: C++ Nov 17th, 2008 |
| Replies: 23 Views: 1,460 const int ANSWER = random_integer1 + random_integer2;
random_integer1 = (rand()%500)+1;
random_integer2 = (rand()%500)+1;
should be |
Forum: C++ Nov 17th, 2008 |
| Replies: 6 Views: 424 |
Forum: C++ Nov 17th, 2008 |
| Replies: 23 Views: 1,460 No problem. Post back if you don't get it working. |
Forum: C++ Nov 17th, 2008 |
| Replies: 4 Views: 1,055 int MAX_NUM = 600851475143;
int max = 0;
vector <int> ints;
for(int i = 1; i <= MAX_NUM; ++i)
if((int)MAX_NUM % i == 0)
ints.push_back(i);
cout << "size = " << ints.size(); |
Forum: C++ Nov 17th, 2008 |
| Replies: 6 Views: 424 Your error is not related to classes here:
You are trying to display a function(displayCargo()) that returns void. Try this:
void Aircraft::listCargo()
{
for (int i = 0; i <... |
Forum: C++ Nov 17th, 2008 |
| Replies: 23 Views: 1,460 replace these "
cin >> answer;
cout << "\n";
return 0;
} "
with that code. You will need to return 0 and close the brace of course :p |
Forum: C++ Nov 17th, 2008 |
| Replies: 23 Views: 1,460 int input;
const int ANSWER = random_integer1 + random_integer2;
do
{
cin >> input; // get input
} while(input != ANSWER);
/* this will repeat as long as input is not equal to the answer.... |
Forum: C++ Nov 17th, 2008 |
| Replies: 6 Views: 424 You can have functions in Cargo that return the details and don't change any value.
class Cargo
{
public:
int get_weight() const {return weight;} // the const here means that this function... |