By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,479 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

Too many types in declaration

P: n/a
Hi,
I'm learning C++, i wrote a small project that has these files:

Log.h
Log.cpp

Render.h
Render.cpp

Tid.h
Tid.cpp

________________________
In TID.h :

#ifndef TID_HPP_INCLUDED
#define TID_HPP_INCLUDED

typedef unsigned char byte;

......
#define EXIT_SUCCESS 0
.....
#define BGI_DRIVER "SVGA64K"
#define BGI_600_480 4
#define SCREEN_WIDTH 600
....
#define LOG_FILE_NAME "log.txt"

#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <mem.h>
#include <stdio.h>

#include "Log.h"
#include "MouseLib.h"
#include "Render.h"

#endif

-----------------------------------
TID.CPP

#include "TiD.h"

int main(void)
{
...........
return EXIT_SUCCESS;
}

___________________
In LOG.h i have:
#ifndef LOG_HPP_INCLUDED
#define LOG_HPP_INCLUDED

void CLog_write(const char *s);
#endif

________________________________
Log.CPP

#include "TID.h"

void CLog_write(const char* s){ ../*write file*/... }
------------------------------------------------------
Render.H
#include "tid.h"

#ifndef RENDER_ENGINE_HPP
#define RENDER_ENGINE_HPP

typedef struct tagBITMAP{
.....} BITMAP;
class CRender
{
public:
CRender();
~CRender();
void fskip(FILE * fp,int);
......
private:
......
}

---------------------------------------------------------
RENDER.CPP

#include "TID.h"

// Initialize graphic mode.
CRender::CRender()
{
/* init BGI driver */
}

void CRender::PutImage (const char * filename,int x,int y,int ops)
const
{
FILE *fp;
....
CLog_write("CRender::PutImage() : Invalid BMP file");
.....
}
....

--------------------------------------------------------

When i compile in TC++ 3.0 i have error message:
Error LOG.CPP 3: Too many types in declaration.
I think the problem maybe about "include header" but i don't know much
about may files and many header, before i wrote simple programs with
1 file (and one header).

Thank for your help.
TLE

Nov 28 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a
tienlx wrote:
Hi,
I'm learning C++, i wrote a small project that has these files:

Log.h
Log.cpp

Render.h
Render.cpp

Tid.h
Tid.cpp

________________________
In TID.h :

#ifndef TID_HPP_INCLUDED
#define TID_HPP_INCLUDED

typedef unsigned char byte;

.....
#define EXIT_SUCCESS 0
....
#define BGI_DRIVER "SVGA64K"
#define BGI_600_480 4
#define SCREEN_WIDTH 600
...
#define LOG_FILE_NAME "log.txt"

#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <mem.h>
#include <stdio.h>

#include "Log.h"
#include "MouseLib.h"
#include "Render.h"

#endif

-----------------------------------
TID.CPP

#include "TiD.h"

int main(void)
{
...........
return EXIT_SUCCESS;
}

___________________
In LOG.h i have:
#ifndef LOG_HPP_INCLUDED
#define LOG_HPP_INCLUDED

void CLog_write(const char *s);
#endif

________________________________
Log.CPP

#include "TID.h"

void CLog_write(const char* s){ ../*write file*/... }
------------------------------------------------------
Render.H
#include "tid.h"

#ifndef RENDER_ENGINE_HPP
#define RENDER_ENGINE_HPP

typedef struct tagBITMAP{
....} BITMAP;
class CRender
{
public:
CRender();
~CRender();
void fskip(FILE * fp,int);
.....
private:
.....
}

---------------------------------------------------------
RENDER.CPP

#include "TID.h"

// Initialize graphic mode.
CRender::CRender()
{
/* init BGI driver */
}

void CRender::PutImage (const char * filename,int x,int y,int ops)
const
{
FILE *fp;
...
CLog_write("CRender::PutImage() : Invalid BMP file");
....
}
...

--------------------------------------------------------

When i compile in TC++ 3.0 i have error message:
Error LOG.CPP 3: Too many types in declaration.
I think the problem maybe about "include header" but i don't know much
about may files and many header, before i wrote simple programs with
1 file (and one header).

Thank for your help.
Nothing sticks out. See the guidelines for posting code:

http://parashift.com/c++-faq-lite/ho...t.html#faq-5.8

Post a minimal but *complete* example that we can copy and paste
unchanged into our editors to see the error you get. (Note that we
don't have non-standard headers like graphics.h, dos.h, or conio.h.)

Cheers! --M

Nov 28 '06 #2

P: n/a
mlimber wrote:
tienlx wrote:
>Hi,
I'm learning C++, i wrote a small project that has these files:
[...]
>------------------------------------------------------
Render.H
#include "tid.h"

#ifndef RENDER_ENGINE_HPP
#define RENDER_ENGINE_HPP

typedef struct tagBITMAP{
....} BITMAP;
class CRender
{
public:
CRender();
~CRender();
void fskip(FILE * fp,int);
.....
private:
.....
}
^^^^
There seems to be a missing semicolon here.
>>
[...]
>
Nothing sticks out.
That's true, it doesn't really "stick out"...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 28 '06 #3

P: n/a

mlimber wrote in message...
>tienlx wrote:
>Hi,
I'm learning C++, i wrote a small project that has these files:
________________________
In TID.h :
#ifndef TID_HPP_INCLUDED
#define TID_HPP_INCLUDED

typedef unsigned char byte;
.....
To OP:

#ifdef EXIT_SUCCESS
#undef EXIT_SUCCESS
>#define EXIT_SUCCESS 0
#endif // #ifdef EXIT_SUCCESS
>....
...
#define LOG_FILE_NAME "log.txt"

#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <mem.h>
#include <stdio.h>
Maybe post to an 'C' NG? <G>
Or....

// >#include <stdlib.h>
#include <cstdlib>

// >#include <conio.h>
// >#include <dos.h>
// >#include <mem.h>
#include <memory>

// >#include <stdio.h>
#include <cstdio>
>--------------------------------------------------------
--
Bob R
POVrookie
Nov 28 '06 #4

P: n/a
On 28 Nov 2006 07:03:19 -0800, "tienlx" <ti*****@gmail.comwrote in
comp.lang.c++:
Hi,
I'm learning C++, i wrote a small project that has these files:
[snip]
When i compile in TC++ 3.0 i have error message:
[snip]
I think the problem maybe about "include header" but i don't know much
about may files and many header, before i wrote simple programs with
1 file (and one header).

Thank for your help.
DO NOT ATTEMPT TO LEARN C++ USING Turbo C++ 3.0!!!

This compiler is more than a dozen years old, and from long before the
C++ language standard. It is an exercise in futility.

If you want to learn C++, get an up to date compiler. There are
several free for download.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 29 '06 #5

P: n/a
tienlx wrote:
class CRender
{
}
Missing semicolon.

You got that rather esoteric error message because the compiler
sees:

class CRender { } int main()

and thinks you are declaring main to return a CRender and an int,
but functions are only allowed to have one return type.

Nov 29 '06 #6

P: n/a
Thanks. I solve that problems.

when compile i have error message:
RENDER.H 14: Declaration syntax error.

I don't know why it happens.

#include <stdio.h>

#ifndef RENDER_ENGINE_HPP
#define RENDER_ENGINE_HPP

typedef struct tagBITMAP
{
unsigned short width;
unsigned short height;
unsigned char pallete[256*3];
unsigned char * data;
}BITMAP;

class CRender
{
public:
// Initialize graphic mode.
CRender();
~CRender();
void ClearScreen();
int GetLastError();
void WaitForRetrace(void);
void SetPalette(byte *palette);
void fskip(FILE * fp,int);
void PutImage (const char * filename,int x,int y,int ops) ;
private:
int m_iGDriver;
int m_iGMode;
int m_iErrorcode;

};

#endif

Nov 29 '06 #7

P: n/a
tienlx wrote:
Thanks. I solve that problems.

when compile i have error message:
RENDER.H 14: Declaration syntax error.
Which one is line 14?
>
I don't know why it happens.
See FAQ 5.8.
>
#include <stdio.h>

#ifndef RENDER_ENGINE_HPP
#define RENDER_ENGINE_HPP

typedef struct tagBITMAP
{
unsigned short width;
unsigned short height;
unsigned char pallete[256*3];
unsigned char * data;
}BITMAP;

class CRender
{
public:
// Initialize graphic mode.
CRender();
~CRender();
void ClearScreen();
int GetLastError();
void WaitForRetrace(void);
void SetPalette(byte *palette);
What's a "byte"?
void fskip(FILE * fp,int);
void PutImage (const char * filename,int x,int y,int ops) ;
private:
int m_iGDriver;
int m_iGMode;
int m_iErrorcode;

};

#endif
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 29 '06 #8

P: n/a
tienlx wrote:
>
when compile i have error message:
RENDER.H 14: Declaration syntax error.

I don't know why it happens.
You need to say which line is line 14, and post the exact
code you are compiling. (For example, "byte" in the code
below is undefined, but that can't be line 14).
#include <stdio.h>

#ifndef RENDER_ENGINE_HPP
#define RENDER_ENGINE_HPP

typedef struct tagBITMAP
{
unsigned short width;
unsigned short height;
unsigned char pallete[256*3];
unsigned char * data;
}BITMAP;
Just a stab in the dark here, but your coding style indicates
you are writing a MS Windows application. MS Windows
header files already define "BITMAP". So if you include
this header after you have included windows.h etc. then
you might get that error.

Nov 29 '06 #9

P: n/a
Here my code (a simple program that put image on screen use SuperVGA
BGI Driver 600x480x256 colors mode):

File Const.h

#ifndef CONST_HPP_INCLUDED
#define CONST_HPP_INCLUDED
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned long dword;

#define EXIT_SUCCESS 0
#define EXIT_FAILED 1
#define ERR_OPEN_FILE 2
#define ERR_MEM_ALLOC 3

#define BGI_DRIVER "SVGA64K"
#define BGI_600_480 4
#define BGI_COLORS 256
#define SCREEN_WIDTH 600
#define SCREEN_HEIGHT 480
#define PALLETE_INDEX 0x03c8
#define PALLETE_DATA 0x03c9
#define INPUT_STATUS 0x03da
#define VRETRACE 0x08

#define LOG_FILE_NAME "log.txt"

#endif
-------------
Render.h

#include <stdio.h>
#include "Const.h"

#ifndef RENDER_ENGINE_HPP
#define RENDER_ENGINE_HPP

typedef struct tagBITMAP
{
word width;
word height;
byte pallete[BGI_COLORS*3];
byte * data;
}BITMAP;

class CRender
{
public:
// Initialize graphic mode.
CRender();
~CRender();
void ClearScreen();
int GetLastError();
void WaitForRetrace(void);
void SetPalette(byte *palette);
void fskip(FILE * fp,int);
void PutImage (const char * filename,int x,int y,int ops) ;
private:
int m_iGDriver,m_iGMode,m_iErrorcode;

};

#endif
When i compile in BC++ 4.5 or TC++ 3.0, i got an error:
Error Render.h 15: Declaration syntax error.

Line 15 is line: " class CRender"

Thank for your help.

Nov 30 '06 #10

P: n/a

"tienlx" <ti*****@gmail.comwrote in message
news:11**********************@16g2000cwy.googlegro ups.com...
Here my code (a simple program that put image on screen use SuperVGA
BGI Driver 600x480x256 colors mode):

File Const.h

#ifndef CONST_HPP_INCLUDED
#define CONST_HPP_INCLUDED
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned long dword;

#define EXIT_SUCCESS 0
#define EXIT_FAILED 1
#define ERR_OPEN_FILE 2
#define ERR_MEM_ALLOC 3

#define BGI_DRIVER "SVGA64K"
#define BGI_600_480 4
#define BGI_COLORS 256
#define SCREEN_WIDTH 600
#define SCREEN_HEIGHT 480
#define PALLETE_INDEX 0x03c8
#define PALLETE_DATA 0x03c9
#define INPUT_STATUS 0x03da
#define VRETRACE 0x08

#define LOG_FILE_NAME "log.txt"

#endif
-------------
Render.h

#include <stdio.h>
#include "Const.h"

#ifndef RENDER_ENGINE_HPP
#define RENDER_ENGINE_HPP

typedef struct tagBITMAP
{
word width;
word height;
byte pallete[BGI_COLORS*3];
byte * data;
}BITMAP;

class CRender
{
public:
// Initialize graphic mode.
CRender();
~CRender();
void ClearScreen();
int GetLastError();
void WaitForRetrace(void);
void SetPalette(byte *palette);
void fskip(FILE * fp,int);
void PutImage (const char * filename,int x,int y,int ops) ;
private:
int m_iGDriver,m_iGMode,m_iErrorcode;

};

#endif
When i compile in BC++ 4.5 or TC++ 3.0, i got an error:
Error Render.h 15: Declaration syntax error.

Line 15 is line: " class CRender"
What happens if you change BITMAP to spoo?
Maybe BITMAP is defined somewhere else.
(All caps are normally reserved for defines BTW)

How about if you remove the typedef for the struct
and do it like c++?

struct tagBitmap{...}

tagBitmap spoo;
....
Nov 30 '06 #11

P: n/a

Duane Hebert wrote:
"tienlx" <ti*****@gmail.comwrote in message
news:11**********************@16g2000cwy.googlegro ups.com...
Here my code (a simple program that put image on screen use SuperVGA
BGI Driver 600x480x256 colors mode):

File Const.h

#ifndef CONST_HPP_INCLUDED
#define CONST_HPP_INCLUDED
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned long dword;

#define EXIT_SUCCESS 0
#define EXIT_FAILED 1
#define ERR_OPEN_FILE 2
#define ERR_MEM_ALLOC 3

#define BGI_DRIVER "SVGA64K"
#define BGI_600_480 4
#define BGI_COLORS 256
#define SCREEN_WIDTH 600
#define SCREEN_HEIGHT 480
#define PALLETE_INDEX 0x03c8
#define PALLETE_DATA 0x03c9
#define INPUT_STATUS 0x03da
#define VRETRACE 0x08

#define LOG_FILE_NAME "log.txt"

#endif
-------------
Render.h

#include <stdio.h>
#include "Const.h"

#ifndef RENDER_ENGINE_HPP
#define RENDER_ENGINE_HPP

typedef struct tagBITMAP
{
word width;
word height;
byte pallete[BGI_COLORS*3];
byte * data;
}BITMAP;

class CRender
{
public:
// Initialize graphic mode.
CRender();
~CRender();
void ClearScreen();
int GetLastError();
void WaitForRetrace(void);
void SetPalette(byte *palette);
void fskip(FILE * fp,int);
void PutImage (const char * filename,int x,int y,int ops) ;
private:
int m_iGDriver,m_iGMode,m_iErrorcode;

};

#endif
When i compile in BC++ 4.5 or TC++ 3.0, i got an error:
Error Render.h 15: Declaration syntax error.

Line 15 is line: " class CRender"

What happens if you change BITMAP to spoo?
Maybe BITMAP is defined somewhere else.
(All caps are normally reserved for defines BTW)

How about if you remove the typedef for the struct
and do it like c++?

struct tagBitmap{...}

tagBitmap spoo;
...

I tried, but it does'nt work.

Nov 30 '06 #12

P: n/a

"tienlx" <ti*****@gmail.comwrote in message
news:11**********************@80g2000cwy.googlegro ups.com...
When i compile in BC++ 4.5 or TC++ 3.0, i got an error:
Error Render.h 15: Declaration syntax error.

Line 15 is line: " class CRender"

What happens if you change BITMAP to spoo?
Maybe BITMAP is defined somewhere else.
(All caps are normally reserved for defines BTW)

How about if you remove the typedef for the struct
and do it like c++?

struct tagBitmap{...}

tagBitmap spoo;
...


I tried, but it does'nt work.
Then I'm out of ideas. You typically get this
sort of error when a preceding declaration is
not terminated properly, for example, an
included header with a class declaration missing
the ;
Nov 30 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.