Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 27th, 2004, 4:47 AM   #1
Amit_Tour
Newbie
 
Join Date: Oct 2004
Posts: 2
Rep Power: 0 Amit_Tour is on a distinguished road
Hey everyone,
I have just signed in to this forum, and it looks real good. I'm now on my first steps on C++, after programming for one year in Java. I have wrote this very basic code:
#include "calculator.h"
class Rational;
{
   Rational::Rational(const Rational rat)
   {
      temp* Rational = new Rational;
    };
};

and got the syntax error before '{' on line 3. What's the problem?

On other issue, why I can't paste texts into my Mozilla browser on Fedora/Red Hat Linux? This is quite annoying...

Thanks, Amit
Amit_Tour is offline   Reply With Quote
Old Oct 27th, 2004, 5:33 AM   #2
jasper_ferrer
Newbie
 
Join Date: Sep 2004
Posts: 23
Rep Power: 0 jasper_ferrer is on a distinguished road
#include "calculator.h" // <- should have a; here
class Rational; // <- remove this;
{
 * * *Rational::Rational(const Rational rat) *// <- move this function definition outside the class body
 * * *{ * * * * * * * * * * * * * * * * * * * * * * * * * * 
 * * * * * *temp* Rational = new Rational; // did you mean Rational *temp?
 * * * }; // <- unnecessary;
};

also your copy constructor looks bad. i think it will not compile. argument should be:

Rational(const Rational &rat)

on the issue of pasting text, try highlighting the text you want to copy, then middle click to paste (make sure the text is still highlighted).
jasper_ferrer is offline   Reply With Quote
Old Oct 27th, 2004, 5:49 AM   #3
Amit_Tour
Newbie
 
Join Date: Oct 2004
Posts: 2
Rep Power: 0 Amit_Tour is on a distinguished road
first, tnx for your detailed answer
second, I would appreciate it if you could explain me this: If I should not declare "class Rational;". then where should I remove the constructor to?

another general question: Why should I declare "Rational::Rational" in the constructor and not just "Rational"?

tnx..
Amit_Tour is offline   Reply With Quote
Old Oct 27th, 2004, 6:49 AM   #4
Draggan
Newbie
 
Join Date: Oct 2004
Posts: 1
Rep Power: 0 Draggan is on a distinguished road
Inside your class Rational should be your function declaration, not the actual definition of the constructor Rational. It should look (roughly) like this:

#include "calculator.h";

class Rational
{
Rational(const Rational &rat); // constructor prototype
};

Rational::Rational(const Rational &rat) // constructor definition
{
temp* Rational = new Rational; // No idea what you want to do here
}

// I haven't debugged this, go try it and see if it works. If you want this to work, both the calculator.h and this file would have to be in the same workspace.
Draggan is offline   Reply With Quote
Old Oct 27th, 2004, 1:41 PM   #5
sirclif
Newbie
 
Join Date: Oct 2004
Posts: 7
Rep Power: 0 sirclif is on a distinguished road
the semi-colon ( is not necessary after the #include statements
sirclif is offline   Reply With Quote
Old Oct 28th, 2004, 3:33 AM   #6
jasper_ferrer
Newbie
 
Join Date: Sep 2004
Posts: 23
Rep Power: 0 jasper_ferrer is on a distinguished road
Quote:

the semi-colon ( is not necessary after the #include statements
i stand corrected.
jasper_ferrer is offline   Reply With Quote
Old Oct 29th, 2004, 7:34 AM   #7
peace_of_mind
Professional Programmer
 
peace_of_mind's Avatar
 
Join Date: Sep 2004
Location: Hell if I know most of the time
Posts: 439
Rep Power: 4 peace_of_mind is on a distinguished road
Send a message via MSN to peace_of_mind Send a message via Yahoo to peace_of_mind
The " .h " is no longer necessary is it? I guess it depends on the compiler used.
__________________
Amateurs built the ark
Professionals built the Titanic

peace_of_mind is offline   Reply With Quote
Old Oct 29th, 2004, 2:03 PM   #8
sirclif
Newbie
 
Join Date: Oct 2004
Posts: 7
Rep Power: 0 sirclif is on a distinguished road
.h is not used for the old C libraries anymore. your supposed to drop the .h and put a c in front of it.
#include <stdlib.h>

becomes

#include <cstdlib>

but you can call your own source files whatever you want. in this case,
#include"calculator.h"
is including a file called calculator.h in the working directory.
it could jsut have well been called calculator, calculator.whatextension, or kkklkj.kkjsk
sirclif is offline   Reply With Quote
Old Oct 31st, 2004, 5:16 AM   #9
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
But please don't call it kkklkj.kkjsk if you're open-sourcing the project.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:22 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC