Jump to content
  • Advertisement
Sign in to follow this  
wabbz111

headers problem

This topic is 3679 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi i am getting into the headers thing in C++ but i have hit a snag here are the errors
In file included from auto_car.cpp:1:
auto_car.h:11: error: expected class-name before '{' token

auto_car.cpp: In function `int main(int, char**)':
auto_car.cpp:10: error: expected primary-expression before "const"
auto_car.cpp:10: error: expected `;' before "const"
auto_car.cpp:17: error: a function-definition is not allowed here before '{' token
auto_car.cpp:17: error: expected `,' or `;' before '{' token

make.exe: *** [auto_car.o] Error 1

Execution terminated

The header file
#ifndef AUTO_CAR_H
#define AUTO_CAR_H


//includes
#include <stdio.h>

//auto namespaces
namespace Auto{
               
          class Car:public VehicleType{
          
          public:
                 
                 const float getSpeed();
                 
                 
                 void setSpeed(const float pSpeed);
                 
          protected:
          
          private:
                  
                  float mSpeed;
                  
                  float mSomeVariable;
                  
          };
     }
     #endif 


and the source file
#include "auto_car.h"
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{

 const float Auto::Car::getSpeed(){
       calculateBrakePower();
       
       
       return Vehicletype::getSpeed();
       }
       
       void Auto::Car::setSpeed(const float pSpeed){
            
            VehicleType::setSpeed(pSpeed);
            
            update();
            
            }

    system("PAUSE");
    return EXIT_SUCCESS;
}


please help.thanks

Share this post


Link to post
Share on other sites
Advertisement
The problem is you have your "Car" class inheriting from some class "VehicleType", which is never defined. If it's defined in some other header you need to include that header before defining "Car".

Share this post


Link to post
Share on other sites
I don't think it's allowed to define functions within another function either. I may be wrong because I'm an idiot, but main() looks a little weird to me.

Within the define function (in the main function) there is a call to calculateBrakePower(). Where is that function defined?

In the header file there is the following declaration;
void setSpeed(const float pSpeed);

What information does the p prefix convey?

Share this post


Link to post
Share on other sites
That's one problem. There's another.

Why are your Auto::Car::getSpeed() and Auto::Car::setSpeed() definitions INSIDE the main() function in the source file? They should be outside...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!