Advertisement Jump to content
Sign in to follow this  

headers problem

This topic is 3830 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

#include <stdio.h>

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

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(){
       return Vehicletype::getSpeed();
       void Auto::Car::setSpeed(const float pSpeed){

    return EXIT_SUCCESS;

please help.thanks

Share this post

Link to post
Share on other sites
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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!