开发者

Supposed "syntax error" in my code,"missing ';' before '.'"

I'm relatively new to this level of coding and am really hitting my wall on this error:

[Line 65] error C2143: syntax error : missing ';' before '.'

Obviously this would usually mean a syntax error in my code, but I can't find it flippin anywhere. Any assistance (or a second set of eyes to see my error would be appreciated).

Here is the code snippet in question:

class RacingCar {

public: 
            Wheel* wheels[4];

            RacingCar()
            { 
                wheels[0] = new Wheel;
                wheels[1] = new Wheel;
                wheels[2] = new Wheel;
                wheels[3] = new Wheel;
            }

            RacingCar( RacingCar& refOldCar)
            {
//              new Wheel(refOldCar.wheels[0]->pressure);
                wheels[0] = new Wheel;
                wheels[1] = new Wheel;
                wheels[2] = new Wheel;
开发者_如何学Go                wheels[3] = new Wheel;

                int a = refOldCar.speedCopy();
                **RacingCar.setSpeed(10);**
                RacingCar.Brake(50);
                RacingCar.Print();
                RacingCar.speed = refOldCar.speed;
            }

Thanks a ton for any help


This:

RacingCar.setSpeed(10);

should be:

setSpeed(10);

which is shorthand for:

this->setSpeed(10);


RacingCar.setSpeed(10);

there is no such syntax. Write:

RacingCar::setSpeed(10);

or

setSpeed(10);

or

this->setSpeed(10);

Note that they all may have different meaning, although will probably work the same in your context.


You are using the Class and Constructor (same as Class) name - e.g. RacingCar instead of refOldCar, this or just directly accessing members.


Since the speed is unlikely to be a class-level property (affecting all cars), you probably meant to write:

this->setSpeed (10); // or, for the less anal, just "setSpeed(10);" :-)

This more correctly makes it an attempt to set the object-level property. A class-level property would reference RacingCar::SomethingOrOther (double-colon rather than dot) which is why it's thinking you need to close off the current statement before that . character.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜