7 Replies - 1939 Views - Last Post: 16 July 2009 - 12:25 AM Rate Topic: -----

#1 deer dance  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 116
  • Joined: 21-April 09

Obscure compiling error and user-made header file

Posted 14 July 2009 - 07:38 PM

I'm currently working on a text based game. So far, it's pretty much just been brain-storming and planning.

I just started coding this evening, but already I'm stuck.

I think the compiling error may have something to do with my header file [august.hpp], but I'm not sure, because this is my first attempt at making a header file.

Here is the main file in the project:
#include <iostream>
using std::cout;
using std::endl;
#include <iomanip>
#include <string>
#include <cstring>
#include "august.hpp"
#include <cmath>

int main()
{
    stats archer;
          archer.atk = 3;
          archer.def = 1;

    cout << "Attack:  " << archer.atk << endl
         << "Defense: " << archer.def << endl;

    getchar();
    return 0;
}





Here's the header file:
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <cstring>

struct stats
{
    int atk;
    int def;
}




And the compiling errors:

Quote

2 C:\Users\*Blah\engine-test.cpp expected unqualified-id before "int"
2 C:\Users\*Blah\engine-test.cpp expected `;' before "int"
2 C:\Users\*Blah\engine-test.cpp declaration does not declare anything
12 C:\Users\*Blah\engine-test.cpp new types may not be defined in a return type
12 C:\Users\*Blah\engine-test.cpp extraneous `int' ignored
12 C:\Users\*Blah\engine-test.cpp `main' must return `int'
C:\Users\*Blah\Makefile.win [Build Error] [engine-test.o] Error 1


And finally, the compiler log:

Quote

Compiler: Default compiler
Building Makefile: "C:\Users\Kristen\Documents\August Engine\Makefile.win"
Executing make...
make.exe -f "C:\Users\Kristen\Documents\August Engine\Makefile.win" all
g++.exe -c engine-test.cpp -o engine-test.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

engine-test.cpp:2: error: expected unqualified-id before "int"

engine-test.cpp:2: error: expected `;' before "int"
engine-test.cpp:2: error: declaration does not declare anything

engine-test.cpp:12: error: new types may not be defined in a return type
engine-test.cpp:12: error: extraneous `int' ignored
engine-test.cpp:12: error: `main' must return `int'

make.exe: *** [engine-test.o] Error 1

Execution terminated


Any help you can provide will be much appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Obscure compiling error and user-made header file

#2 Mowgef  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 245
  • Joined: 01-May 09

Re: Obscure compiling error and user-made header file

Posted 14 July 2009 - 07:52 PM

I'm not entirely sure but are you supposed to have includes in your .h file?
Was This Post Helpful? 0
  • +
  • -

#3 deer dance  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 116
  • Joined: 21-April 09

Re: Obscure compiling error and user-made header file

Posted 14 July 2009 - 07:56 PM

...
Did you read past the first code block?
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6245
  • View blog
  • Posts: 24,013
  • Joined: 23-August 08

Re: Obscure compiling error and user-made header file

Posted 15 July 2009 - 03:35 AM

Add a semi-colon after the definition of struct stats. And you don't need the includes in the header file, as there's nothing in the header file that requires them.
Was This Post Helpful? 0
  • +
  • -

#5 junxuan  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 44
  • Joined: 25-March 09

Re: Obscure compiling error and user-made header file

Posted 15 July 2009 - 07:21 AM

just to slightly elaborate the above post, the syntax of a struct should be :

struct nameOfStruct{

	random variables;

};


note the semi colon u missed out.

This post has been edited by junxuan: 15 July 2009 - 07:23 AM

Was This Post Helpful? 0
  • +
  • -

#6 deer dance  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 116
  • Joined: 21-April 09

Re: Obscure compiling error and user-made header file

Posted 15 July 2009 - 01:12 PM

Thank you, I'll check to see if that'll work.

And though at this point, the header file doesn't seem necessary, it will be.

It's going to be an engine for the game to follow.

I just started building it.


EDIT:

And it works!

Thank you again.

My problem is fixed.

This post has been edited by deer dance: 15 July 2009 - 01:18 PM

Was This Post Helpful? 0
  • +
  • -

#7 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Obscure compiling error and user-made header file

Posted 15 July 2009 - 02:32 PM

You will want to place something in your header to ensure that its contents only get included once. For example:

#pragma once
#ifndef AUGUST_HPP
#define AUGUST_HPP

struct stats
{
	int atk;
	int def;
};

#endif


The line#pragma once is really all you need in some compilers (VC++) but the preprocessor structure is more common and work on all compiler. This will keep the compiler from trying to redefine items as the header is used across your program.
Was This Post Helpful? 0
  • +
  • -

#8 deer dance  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 116
  • Joined: 21-April 09

Re: Obscure compiling error and user-made header file

Posted 16 July 2009 - 12:25 AM

Thank you, I'll implement that into the header file.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1