![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Oct 2004
Posts: 2
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Sep 2004
Posts: 23
Rep Power: 0
![]() |
#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). |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Oct 2004
Posts: 2
Rep Power: 0
![]() |
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.. |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Oct 2004
Posts: 1
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Oct 2004
Posts: 7
Rep Power: 0
![]() |
the semi-colon (
is not necessary after the #include statements |
|
|
|
|
|
#6 | |
|
Newbie
Join Date: Sep 2004
Posts: 23
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
|
|
#7 |
|
Professional Programmer
|
The " .h " is no longer necessary is it? I guess it depends on the compiler used.
__________________
Amateurs built the ark Professionals built the Titanic |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Oct 2004
Posts: 7
Rep Power: 0
![]() |
.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" it could jsut have well been called calculator, calculator.whatextension, or kkklkj.kkjsk |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|