Too many types in declaration

T

tienlx

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
 
M

mlimber

tienlx said:
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/how-to-post.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
 
V

Victor Bazarov

mlimber said:
tienlx said:
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
 
B

BobR

mlimber wrote in message...
To OP:

#ifdef EXIT_SUCCESS
#undef EXIT_SUCCESS

#endif // #ifdef EXIT_SUCCESS

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>
 
J

Jack Klein

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.
 
O

Old Wolf

tienlx said:
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.
 
T

tienlx

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
 
V

Victor Bazarov

tienlx said:
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
 
O

Old Wolf

tienlx said:
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.
 
T

tienlx

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.
 
D

Duane Hebert

tienlx said:
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;
....
 
T

tienlx

Duane said:
tienlx said:
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.
 
D

Duane Hebert

tienlx said:
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 ;
 
Joined
Jul 28, 2009
Messages
3
Reaction score
0
i have written this program and this is giving just one error and that is "too many types in declaration".Please help..........

#include<iostream.h>
class invent2
class invent1
{
int code,items;
float price;
public:
invent1(int a,int b,float c)
{
code=a;
items=b;
price=c;
}
void putdata()
{
cout<<"Code: "<<code<<"\n";
cout<<"Items: "<<items<<"\n";
cout<<"Price: "<<price<<"\n";
}
int getcode(){return code;}
int getitems(){return items;}
float getprice(){return price;}
operator float(){return(items*price);}
/*operator invent2()
{
invent2 temp;
temp.code=code;
temp.value=price*items;
return temp;
}*/
};
class invent2
{
int code;
float value;
public:
invent2()
{
code=0;
value=0;
}
invent2(int x,float y)
{
code=x;
value=y;
}
void putdata()
{
cout<<"Code: "<<code<<"\n";
cout<<"Value: "<<value<<"\n\n";
}
invent2(invent1 p)
{
code=p.getcode();
value=p.getitems() * p.getprice();
}
};
int main()
{
invent1 s1(100,5,140.0);
invent2 d1;
float total_value;
total_value=s1;
d1=s1;
cout<<"Product details-invent1 type"<<"\n";
s1.putdata();
cout<<"\nStock value"<<"\n";
cout<<"Value= "<<total_value<<"\n\n";
cout<<"Product details-invent2 type"<<"\n";
d1.putdata();
return 0;
}
 
Joined
Jul 28, 2009
Messages
3
Reaction score
0
Mathematical operations on strings

i m not able to make a new post.so m writin my problm in this post only.if sm1 can help do help.n also tell me how to make a new post...
This program has many errors,plz help..

#include<string.h>
#include<iostream.h>
class string
{
char*p;
int len;
public:
string(){len=0; p=0;}
string(const char*s);
string(const string & s);
~sting(){delete p;}
friend string operator+(const string &s,const string &t);
friend int operator<=(const string &s,const string &t);
friend void show(const string s);
};
string::string(const char*s)
{
len=strlen(s);
p=new char[len+1];
strcopy(p,s);
}
string::string(const string & s)
{
len= s.len;
p= new char[len+1];
strcpy(p,s.p);
}
string operator+(const string &s,const string &t)
{
string temp;
temp.len=s.len+t.len;
temp.p=new char[temp.len+1];
strcpy(temp.p,s.p);
strcat(temp.p,t.p);
return(temp);
}
int operator<=(const string &s,const string &t)
{
int m=strlen(s.p);
int n=strlen(t.p);
if (m<=n)return(1);
else return(0);
}
void show(const string s)
{
cout<<s.p;
}
int main()
{
string s1="NEW";
string s2="YORK";
string s3="DELHI";
string t1,t2,t3;
t1=s1;
t2=s2;
t3=s1+s2;
cout<<"\nt1= ";show(t1);
cout<<"\nt2= ";show(t2);
cout<<"\n";
cout<<"\nt3= ";show(t3);
cout<<"\n\n";
if(t1<=t3)
{
show(t1);
cout<<"smaller than";
show(t3);
cout<<"\n";
}
else
{
show(t3);
cout<<"smaller than";
show(t1);
cout<<"\n";
}
return 0;
}
 
Joined
Jul 28, 2009
Messages
3
Reaction score
0
Overloading operators using friend

this also has many errors,plz help..

#include<iostream.h>
const size=3;
class vector
{
int v[size];
public:
vector();
vector(int *x);
friend vector operator*(int a,vector b);
friend vector operator*(vector b,int a);
friend istream & operator>>(istream &,vector &);
friend ostream & operator>>(ostream &,vector &);
};
vector::vector()
{
for(int i=0; i<size; i++)
v=0;
}
vector::vector(int *x)
{
for(int i=0;i<size; i++)
v=x;
}
vector operator*(int a,vector b);
{
vector c;
for(int i=0; i<size; i++)
c.v=a*b.v;
return c;
}
vector operator*(vector b,int a)
{
vector c;
for(int i=0; i<size; i++)
c.v=b.v*a;
return c;
}
istream & operator>>(istream &din,vector &b)
{
for(int i=0; i<size; i++)
din>>b.v;
return (din);
}
ostream & operator<<(ostream &dout,vector &b)
{
dout<<"("<<b.v[0];
for(int i=0; i<size; i++)
dout<<","<<b.v;
dout<<")";
return(dout);
}
int x[size]={2,4,6};
int main()
{
vector m;
vector n=x;
cout<<"Enter elements of vector m"<<"\n";
cin>>m;
cout<<"\n";
cout<<"m= "<<m<<'\n";
vector p,q;
p=2*m;
q=n*2;
cout<<"\n";
cout<<"p= "<<p<<"\n";
cout<<"q= "<<q<<"\n";
return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,266
Messages
2,571,072
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top