Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,952 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,324 people online right now. Registration is fast and FREE... Join Now!




having trouble getting my class recognized

 
Reply to this topicStart new topic

having trouble getting my class recognized, I don't know why the computer doesn't recognize my class

cwc123188
4 Dec, 2007 - 01:38 PM
Post #1

New D.I.C Head
*

Joined: 5 Nov, 2007
Posts: 5

First of all, thanks for trying to answer my question. smile.gif
I am working on a lunar lander class and I have written most of its header file and its implementation(.cpp). I also wrote a extremely simple driver program that tests the class but I encounter a problem that I can't solve on my own.
When I try to compile, an error message comes up saying, "left of '.get_crt_alt' must have class/struct/union."

In order, below are the driver program, header file, and the implementation of class Lander. Please take a look at them and help me if you can!

CODE

// FILE: main.cpp
// MAIN PROGRAM OF THE LUNAR LANDER GAME THAT USES CLASS Lander

#include "Lander.h"
#include <iostream>
using namespace std;

int main()
{
    Lander myLander(float, float, float, float, float, float, float);
    cout << myLander.get_crt_alt();

    return 0;
}



CODE

// FILE: Lander.h
// HEADER FILE FOR CLASS Lander

#ifndef LANDER_H
#define LANDER_H

const float SRATE = 0;                        // DEFAULT STARTING FUEL FLOW RATE (AS A FRACTION OF THE MAXIMUM FUEL CONSUMPTION RATE)
const float SVSPEED = 0;                    // DEFAULT VERTICAL SPEED
const float SALT = 1000;                    // DEFAULT STARTING ALTITUDE
const float SFUELAMOUNT = 1700;                // DEFAULT STARTING FULE AMOUNT
const float LANDERMASS = 900;                // DEFAULT LANDER MASS
const float MAXTHRUST = 5000;                // DEFAULT MAXIMUM ENGINE THRUST
const float MAXRATE = 10;                    // DEFAULT MAXIMUM FUEL CONSUMPTION RATE



class Lander
{
    public:
        // CONSTRUCTORS
        Lander(float, float, float, float, float, float, float);
        // ACCESSOR FUNCTIONS
        float get_crt_rt() const;            // GET CURRENT FUEL FLOW RATE
        float get_crt_vs() const;            // GET CURRENT VERTICAL SPEED
        float get_crt_alt() const;            // GET CURRENT ALTITUDE
        float get_crt_am() const;            // GET CURRENT FUEL AMOUNT
        float get_crt_ms() const;            // GET CURRENT LANDER MASS
        float get_max_ts() const;            // GET MAXIMUM ENGINE THRUST
        float get_max_rt() const;            // GET MAXIMUM FUEL FLOW RATE

        // MUTATOR FUNCTIONS
        void time(float);                    // TIME PASSAGE FUNCTION THAT UPDATES THE VALUES OF crt_rt, crt_vs, crt_alt, crt_am
        void chgflow(float);                // FUNCTION THAT

    private:
        // DATA MEMBERS
        float crt_rt;                        // CURRENT FUEL FLOW RATE                    
        float crt_vs;                        // CURRENT VERTICAL SPEED
        float crt_alt;                        // CURRENT ALTITUDE
        float crt_am;                        // CURRENT FUEL AMOUNT
        float crt_ms;                        // CURRNET LANDER MASS
        float max_ts;                        // MAXIMUM ENGINE THRUST
        float max_rt;                        // MAXIMUM FUEL FLOW RATE

};
#endif // LANDER_H


CODE

// FILE: Lander.cpp
// IMPLEMENTATION FOR CLASS Lander

#include "Lander.h"
#include <iostream>
using namespace std;

Lander::Lander(float crt_rt, float crt_vs, float crt_alt, float crt_am, float crt_ms, float max_ts, float max_rt )
{
    crt_rt = SRATE;
    crt_vs = SVSPEED;
    crt_alt = SALT;
    crt_am = SFUELAMOUNT;
    crt_ms = LANDERMASS;
    max_ts = MAXTHRUST;
    max_rt = MAXRATE;
}
float Lander::get_crt_rt() const
{
    return crt_rt;
}
float Lander::get_crt_vs() const
{
    return crt_vs;
}
float Lander::get_crt_alt() const
{
    return crt_alt;
}
float Lander::get_crt_am() const
{
    return crt_am;
}
float Lander::get_crt_ms() const
{
    return crt_ms;
}
float Lander::get_max_rt() const
{
    return max_rt;
}
float Lander::get_max_ts() const
{
    return max_ts;
}
void Lander::time(float t)
{
    // 1. IF OUT OF FUEL, CHECK THROTTLE/ if(crt_am = 0)................
    // 2. CHANGE VELOCITY/ crt_vs +=
    // 3. CHANGE ALTITUDE/ crt_alt -=
    // 4. REDUCE REMAINING FUEL / crt_am -=
    // 5. IF THE ALTITUDE < 0, SET TO ZERO/ if(crt_alt <0)/ crt_alt = 0
    // 6. IF OUT OF FUEL, SET TO ZERO/ if(crt_am < 0)/ crt_am = 0
}
void Lander::chgflow(float f)
{
    crt_rt = f;
}

User is offlineProfile CardPM
+Quote Post

skaoth
RE: Having Trouble Getting My Class Recognized
4 Dec, 2007 - 02:09 PM
Post #2

D.I.C Regular
Group Icon

Joined: 7 Nov, 2007
Posts: 356



Thanked: 12 times
Dream Kudos: 100
My Contributions
I beleive the issue has to do with your constructor

CODE

// This is how you defined and implemented it

// From Lander.h file
Lander(float, float, float, float, float, float, float);

// From Lander.cpp
Lander::Lander(float crt_rt, float crt_vs, float crt_alt, float crt_am, float crt_ms, float max_ts, float max_rt )
{
   crt_rt = SRATE;
    // ...
    // Omitted for clarith
}


It doesn't make any sense to do this because all of the values you are initializing
are private data members of your Lander class. The variable names in your constructor
are named the same as the private data members of your Lander class, if you want to do this
they need to have different names.

Lastly, in main you tried to create your object like this
CODE

// From main.cpp
Lander myLander(float, float, float, float, float, float, float);


The constructor of your class is expecting a "real" float value not the keyword float e.g: Lander yLander(1, 2, 3, 4, 5, 6, 7);
What it looks like you want is a default constructor, or have two constructors, a default and explict.

Cheers


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 05:47PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month