Forum: C++ Aug 7th, 2009 |
| Replies: 7 Views: 288 |
Forum: C++ Aug 7th, 2009 |
| Replies: 7 Views: 288 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: 592 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: 592 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: 910 You can do that:
bool checkUnsignedInt(const string &str)
{
return atoi(str.c_str()) >= 0;
} |
Forum: C Jan 10th, 2009 |
| Replies: 26 Views: 1,175 Nothing. Now show us the complete program. also use the typedef for the struct like I told you. |
Forum: C Jan 10th, 2009 |
| Replies: 26 Views: 1,175 Yes.
In main, it's a better idea to actually create an oject
int main()
{
struct mytype mt = fundCalculation(....) |
Forum: C Jan 10th, 2009 |
| Replies: 26 Views: 1,175 The function is correct, but you don't call it correctly.
Create 3 variables in main x, y, z, give them values and pass their address to the function. |
Forum: C Jan 10th, 2009 |
| Replies: 26 Views: 1,175 #include<stdio.h>
struct mytype
{
int ok;
char ch;
};
struct mytype fundCalculation(int a,int b,int c)
{
struct mytype tmp; |
Forum: C Jan 10th, 2009 |
| Replies: 26 Views: 1,175 Yes, but use our function that returns the struct. |
Forum: C++ Jan 10th, 2009 |
| Replies: 4 Views: 279 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: 26 Views: 1,175 Then instead of ints in the argument list, use pointers to ints.
a pointer to int: int *a = 0;
when you call the function, you need to pass addresses.
so
int x = 4;... |
Forum: C Jan 10th, 2009 |
| Replies: 26 Views: 1,175 Well it works, good job!
Some tips:
Use this form when declaring a struct.
typedef struct
{
int ok;
char ch;
} mytype; |
Forum: C Jan 10th, 2009 |
| Replies: 26 Views: 1,175 Ok, let's go step by step.
We will create a struct that has two members, a char and an int.
Go on and declare the struct. |
Forum: C Jan 10th, 2009 |
| Replies: 26 Views: 1,175 Do you want the function to take pointers as parameters or return a pointer or both?
And why do you want to return 1? |
Forum: C Jan 10th, 2009 |
| Replies: 26 Views: 1,175 So 1 has to be returned for you to know that the result is the third number. You can do it with only one return value:
char arithmeticOperation(int a, int b, int c)
{
// +
if(a + b == c)... |
Forum: C Jan 10th, 2009 |
| Replies: 26 Views: 1,175 You can't return two values from a functio using the return statement. Use a struct as you've been told to above:
typedef struct
{
int x, y;
} P;
P getPoint()
{ |
Forum: C++ Jan 10th, 2009 |
| Replies: 5 Views: 353 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: 279 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: 924 Try darkGDK, it's free and very easy to use. Google it. |
Forum: C++ Dec 7th, 2008 |
| Replies: 3 Views: 459 |
Forum: C++ Dec 6th, 2008 |
| Replies: 3 Views: 459 #ifndef DARK_OBJECT_H
#define DARK_OBJECT_H
#include "DarkGDK.h"
namespace DarkObject
{
class Object // abstract
{
public: |
Forum: C Nov 27th, 2008 |
| Replies: 13 Views: 1,728 #include <stdlib.h> /* needed for rand() function */
#include <time.h> /*needed to call srand() (explained below)*/
int main(void)
{
int r = 0;
/* by calling this function, we seed the... |
Forum: C++ Nov 27th, 2008 |
| Replies: 3 Views: 1,917 void increment(const Machine &aMachine, int amount = 1)
{
rackID = rackID - amount;
}
1. You are... |
Forum: C++ Nov 25th, 2008 |
| Replies: 7 Views: 405 |
Forum: C++ Nov 25th, 2008 |
| Replies: 8 Views: 1,639 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: 405 This is just used to show how it's done :) |
Forum: C++ Nov 25th, 2008 |
| Replies: 7 Views: 405 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: 405 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: 805 Read this:
http://www.daniweb.com/forums/announcement8-3.html |
Forum: C++ Nov 21st, 2008 |
| Replies: 1 Views: 319 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 21st, 2008 |
| Replies: 5 Views: 817 There are a couple of tutorials here (http://www.cprogramming.com/tutorial.html). |
Forum: C++ Nov 17th, 2008 |
| Replies: 3 Views: 325 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: 812 Exactly. It's the assignment operator in PASCAL and used in pseudocode as well. |
Forum: C++ Nov 17th, 2008 |
| Replies: 5 Views: 812 Why don't you write this program and see the results? |
Forum: C++ Nov 17th, 2008 |
| Replies: 20 Views: 980 Do you have to make the class? |
Forum: C++ Nov 17th, 2008 |
| Replies: 25 Views: 59,731 |
Forum: C++ Nov 17th, 2008 |
| Replies: 20 Views: 980 Ok.Isn't it an object? (a class) |