Error multiple types in one declaration

I am using Code::Blocks and Mingw32 with the SDL libraries. The error appears at line 13 of my code (commented below). After some searching I believed it to be a missing semicolon(;), this doesn't

I am using Code::Blocks and Mingw32 with the SDL libraries. The error appears at line 13 of my code (commented below).

After some searching I believed it to be a missing semicolon(;), this doesn’t appear to be the case here though. Additional research threw up the fact that it may be an error in an include file.

Unfortunately there are no errors in the includes and even when the include is commented out this error persists. When the enum block is commented out the error jumps to the end of the class declaration.

#ifndef _TILE_H_
#define _TILE_H_

#include "Define.h"

enum
{
    TILE_TYPE_NONE = 0,
    TILE_TYPE_GROUND,
    TILE_TYPE_RAMPUP,
    TILE_TYPE_RAISED,
    TILE_TYPE_RAMPDOWN
}; //error occurs here (line 13)

class Tile
{
public:
    int TileID;
    int TypeID;

public:
    Tile();
};

#endif

This actually started happening after adding a new class, however the new class is completely unrelated and does not use, include or inherit from the posted one at all.

Any advice or information would be really appreciated.

EDIT (adding Define.h):

#ifndef _DEFINE_H_
#define _DEFINE_H_

#define MAP_WIDTH 40
#define MAP_HEIGHT 40

#define TILE_SIZE 16

#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480

#endif

  • Forum
  • Beginners
  • multiple types in one declaration

multiple types in one declaration

Here is my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef QUEUE_H
#define QUEUE_H
#include "Message.h"
#include <iostream>
using namespace std;

class Node
{
      public:
             Message msg;
             Node* next;
}

class Queue
{
      public:
             Node *front;
             Node *rear;
             int numItems;
             
             Queue()
             {
                    front = NULL;
                    rear = NULL;
                    numItems = 0;
             }
             
             void add(Message m)
             {
                  Node *newnode;
                  newnode = new Node();
                  newnode->msg = m;
                  newnode->next = NULL;
                  
                  if(isEmpty())
                  {
                       front = newnode;
                       rear = newnode;
                  }
                  else
                  {
                       rear->next = newnode;
                       rear = newnode;
                  }
                  numItems++;
             }
             
             void remove(Message &m)
             {
                  Node *temp;
                  if(isEmpty())
                  {
                       cout << "The queue is emptyn";
                  }
                  else
                  {
                       m = front->msg;
                       temp = front;
                       front = front->next;
                       delete temp;
                       numItems--;
                  }
             }
             
             bool isEmpty() const
             {
                  bool status;
                  if(numItems>0)
                      status = false;
                  else
                      status = true;
                  return status;
             }
             
             bool isFull()
             {
                  return false;
             }
             
             int size()
             {
                 return numItems;
             }
};
#endif 

There is error: «multiple types in one declaration». I couldn’t find out where mistake is.

Last edited on

try putting a ; after the } on line 12…

thank you

Topic archived. No new replies allowed.

Почему я получаю "multiple types in one declaration" ошибка при компиляции моей программы на C ++?

8 ответы

Вероятно, у вас есть код, эквивалентный

int float x;

вероятно

class Foo { } float x;

или в более распространенной форме (обратите внимание на отсутствующую точку с запятой после закрывающей фигурной скобки)

class Foo {
  //
}

float x;

ответ дан 07 апр.

Не забудьте проверить ; после объявлений enum тоже.

Создан 20 ноя.

У меня такая же проблема. Иногда в строке ошибки отображается неправильное место. Просмотрите все вновь созданные / измененные классы и посмотрите, не забыли ли вы «;» в конце определения класса.

Создан 02 сен.

Вы должны дважды объявить одну и ту же переменную в каком-то классе или в двух классах с одним и тем же именем. Видеть это на Stack Overflow, например.

Вам также может не хватать ; или у вас может быть определение класса с нарушенным синтаксисом …

Если бы вы могли показать нам какой-нибудь код, это было бы лучше!

ответ дан 23 мая ’17, 12:05

Я предполагаю, что вам не хватает закрывающей скобки где-то в определении класса или точки с запятой после нее.

Создан 18 ноя.

Кроме того, вы могли забыть точку с запятой в предварительном объявлении:

class Foo // <-- forgot semicolon

class Bar {
  ...
};

Создан 03 июн.

Вот еще один сценарий, который может вызвать ту же ошибку.

struct Field
{   // <------ Forget this curly brace
    enum FieldEnum
    {
        FIRSTNAME,
        MIDDLENAME,
        LASTNAME,
        UNKNOWN
    };
};

ответ дан 29 мая ’15, 05:05

Согласитесь с вышеизложенным. Кроме того, если вы видите это, выполните предварительную обработку приложения и посмотрите на .i Найдите «оскорбительное» имя. Затем посмотрите вверх. Вы часто будете видеть «}» без «;» на классе в первом без пробела выше. Найти проблему зачастую труднее, чем понять, в чем она заключается.

ответ дан 07 мая ’16, 17:05

Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками

c++

or задайте свой вопрос.

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
using namespace std;
class part
{
      public:
             part(){i=10;}
             part(int item){i=item;}
             ~part(){}
             
             
             part *next;
             int i;
};
class partList
{
      public:
             //êîíñòðóêòîð,äåñòðóêòîð,êîíñòðóêòîð êîïèðîâàíèÿ.
             partList(){countOfPart++;begin=new part;first=new part;begin->next=first;}
             partList(int a)
             {
                          countOfPart++;
                          begin=new part(a);
                          first=new part;
                          begin->next=first;
             }
             partList(int a,int b)
             {
                          countOfPart+=2;
                          begin=new part(a);
                          first=new part;
                          begin->next=first;
                          add(b);
             }
             ~partList(){delete p;delete first;delete begin;}
             int add(int a)
             {
                 p=new part(a);
                 first->next=p;
                 first=p;
                 countOfPart++;
                 return countOfPart;
             }
             void show()
             {
                  cout<<begin->i<<endl;
                  while(first)
                  {
                  cout<<first->i<<endl; 
                  first=first->next;
                  }
             }
      private:
              int countOfPart;
              part *p;
              part *first;
              part *begin;
              
};
 
int main ( )
{
    partList list(10,20);
    list.add(30);
    list.show();
    system("pause");
    return 0;
}

Подскажите,почему программа зацикилвается?
Даже при таком варианте..

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
using namespace std;
class part
{
      public:
             part(){i=10;}
             part(int item){i=item;}
             ~part(){}
             
             
             part *next;
             int i;
};
class partList
{
      public:
             //êîíñòðóêòîð,äåñòðóêòîð,êîíñòðóêòîð êîïèðîâàíèÿ.
             partList(){countOfPart++;begin=new part;first=new part;begin->next=first;}
             partList(int a)
             {
                          countOfPart++;
                          begin=new part(a);
                          first=new part;
                          begin->next=first;
             }
             partList(int a,int b)
             {
                          countOfPart+=2;
                          begin=new part(a);
                          first=new part;
                          begin->next=first;
                          add(b);
             }
             ~partList(){delete p;delete first;delete begin;}
             int add(int a)
             {
                 p=new part(a);
                 first->next=p;
                 first=p;
                 countOfPart++;
                 return countOfPart;
             }
             void show()
             {
                  cout<<begin->i<<endl;
                  while(true)
                  {
                  if(first==NULL) break;
                  cout<<first->i<<endl; 
                  first=first->next;
                  }
             }
      private:
              int countOfPart;
              part *p;
              part *first;
              part *begin;
              
};
 
int main ( )
{
    partList list(10,20);
    list.add(30);
    list.show();
    system("pause");
    return 0;
}

Добавлено через 11 минут
alsav22, ???

Добавлено через 3 минуты
Помогите,ребят! Второй день разобраться не могу..

Добавлено через 24 минуты
В общем немного поигрался ,и вот что вышло.

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
using namespace std;
class part
{
      public:
             part(){i=10;}
             part(int item){i=item;}
             ~part(){}
             
             
             part *next;
             int i;
};
class partList
{
      public:
             //êîíñòðóêòîð,äåñòðóêòîð,êîíñòðóêòîð êîïèðîâàíèÿ.
             partList(){countOfPart++;begin=new part;first=new part;begin->next=first;}
             partList(int a)
             {
                          countOfPart++;
                          first=new part(a);
             }
             partList(int a,int b)
             {
                          first=new part(a);
                          first->next=0;
                          add(b);
             }
             ~partList(){delete p;delete first;delete begin;}
             int add(int a)
             {
                 p=new part(a);
                 p->next=first;
                 first=p;
                 countOfPart++;
                 return countOfPart;
             }
             void show()
             {
                   while(first)
                   {
                         cout<<first->i<<endl;
                         first=first->next;
                   }
                   
             }
      private:
              int countOfPart;
              part *p;
              part *first;
              part *begin;
              
};
 
int main ( )
{
    partList list(10,20);
    list.add(30);
    int i;
    while(true)
    {
               cin>>i;
               if(i!=0)
               {
                       list.add(i);
               }
               else break;
    }
    list.show();
    system("pause");
    return 0;
}

Проблема в том,что выводится лишь с конца к началу.Как сделать чтобы выводилось и наоборот?

I am sorry for consistently coming here at every little problem, but I just couldn’t find this one after scanning the entire code about ten times over.

I have an error coming from line number 39, which is the end of the block for my declaration of the ‘Paddle’ class: «multiple types in one declaration».

I have also gotten the same error on and off for the SAME code on the line describing my inline getY function. When the error code comes up for getY, it doesn’t come up for the end of the class block.

Any help?


/*This is going to be pong. Tetris comes later*/
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>

const int MAX_PLAYERS = 4;
const int DIM = 600;
SDL_Surface *screen = SDL_SetVideoMode(DIM, DIM, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);


class Ball
{
      int posX;
      int posY;
      public:
}

class Paddle
{
      private:
              int posX;
              int posY;
              //SDLKey keycheck[];
              SDL_Surface *image;
              int type;
              bool touchingR;
              bool touchingL;
              //the touch goes in a clockwise direction. R is the paddles right. L is the left;
      public:
             static int x[];
             static int y[];
             Paddle(int playNumber);
             ~Paddle();
             int getX() {return posX;}
             int getY() {return posY;}
             void setX(int x) {posX = x;}
             void setY(int y) {posY = y;}
             void drawANDcheck();
};

Paddle::Paddle(int playNumber)
{
                switch(playNumber)
                {
                       case 1:
                            posX = 10;
                            posY = DIM/2 - 50;
                            image = SDL_DisplayFormat(SDL_LoadBMP("player1.bmp"));
                            //keycheck[0] = SDLK_q;
                            //keycheck[1] = SDLK_a;
                            type = 1;
                            touchingL = false;
                            touchingR = false;
                            break;
                       case 2:
                            posX = DIM - 20;
                            posY = DIM/2 - 50;
                            image = SDL_DisplayFormat(SDL_LoadBMP("player1.bmp"));
                            //keycheck[0] = SDLK_UP;
                            //keycheck[1] = SDLK_DOWN;
                            type = 2;
                            touchingL = false;
                            touchingR = false;
                            break;
                       case 3:
                            posX = DIM/2 - 50;
                            posY = DIM - 20;
                            image = SDL_DisplayFormat(SDL_LoadBMP("player3.bmp"));
                            //keycheck[0] = SDLK_x;
                            //keycheck[1] = SDLK_c;
                            type = 3;
                            touchingL = false;
                            touchingR = false;
                            break;
                       case 4:
                            posX = DIM/2 - 50;
                            posY = 10;
                            image = SDL_DisplayFormat(SDL_LoadBMP("player3.bmp"));
                            //keycheck[0] = SDLK_h;
                            //keycheck[1] = SDLK_j;
                            type = 4;
                            touchingL = false;
                            touchingR = false;
                            break;
                       //type: 1<   2>  3v    4^
                }
}

Paddle::~Paddle()
{
}

void Paddle::drawANDcheck()
{
     SDL_Event event;
     SDL_Rect *dst;
     
     if(type == 1 || type == 2)
     {
             dst->w = 10;
             dst->h = 100;
     }
     if(type == 3 || type == 4)
     {
             dst->w = 100;
             dst->h = 10;
     }
     
     dst->x = posX;
     dst->y = posY;
     SDL_BlitSurface(image, NULL, screen, dst);
     //checking is seperated for ease of reading
     switch(type)
     {
             case 1:
                  if(posY == 0)
                  {
                  touchingL = true;
                  }
                  if(posY == DIM)
                  {
                  touchingR = true;
                  }
                  while(SDL_PollEvent(&event))
                  {
                  switch(event.key.keysym.sym)
                  {
                                              case SDLK_q:
                                                   posY +=4;
                                              case SDLK_a:
                                                   posY -=4;
                                              
                  }
                  }
             case 2:
                  if(posY == 0)
                  {
                  touchingR = true;
                  }
                  if(posY == DIM)
                  {
                  touchingL = true;
                  }
                  while(SDL_PollEvent(&event))
                  {
                  switch(event.key.keysym.sym)
                  {
                                              case SDLK_UP:
                                                   posY +=4;
                                              case SDLK_DOWN:
                                                   posY -=4;
                                              
                  }
                  }
             case 3:
                  if(posX == 0)
                  {
                  touchingL = true;
                  }
                  if(posX == DIM)
                  {
                  touchingR = true;
                  }
                  while(SDL_PollEvent(&event))
                  {
                  switch(event.key.keysym.sym)
                  {
                  case SDLK_x:
                  posX -=4;
                  case SDLK_c:
                  posX +=4;
                                              
                  }
                  }
             case 4:
                  if(posX == 0)
                  {
                   touchingR = true;
                  }
                   if(posX == DIM)
                  {
                   touchingL = true;
                  }
                  
                  while(SDL_PollEvent(&event))
                  {
                  switch(event.key.keysym.sym)
                  {
                                              case SDLK_h:
                                                   posX -=4;
                                              case SDLK_j:
                                                   posX +=4;
                                              
                  }
                  }
     }
}


int main(int argc, char *argv[])
{
    bool running = true;
    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1)
    {
                                return 0;
    }
atexit (SDL_Quit);

//game-code starts here :)

while(running)
{
              bool start_screen = true;
              bool playing = false;
              SDL_Delay(1);
              SDL_Flip(screen);
              
              while(start_screen)
              {
                                 SDL_Event event;
                                 while(SDL_PollEvent(&event))
                                 {
                                                            
                                 }
                                 Paddle a = Paddle(1);
                                 Paddle b = Paddle(2);
                                 
                                 a.drawANDcheck();
                                 b.drawANDcheck();
                                 
              }
}


return 0;
}

*After Argument*P1: What was it about?P2: Something involving a chair, a cat, and a rubber ducky…

You have to put a «;» after a class declaration.

class Ball {
public:
Thippity-Bleah();
private:
int penguin;
};

If you don’t put that ; at the end of the declaration block then it will think you’re doing something really strange with the Ball class and the Paddle class.

EDIT: Ahh, you have a ; after your Paddle class declaration so I doubt any explanation was necessary — just a typing mistake. Those can be surprisingly nasty. :)

It only takes one mistake to wake up dead the next morning.

Meh…

It could be the actual compiler having an error… I’ma check the bloodshed.net site…

Actually…

Wow. Thanks, you just reminded me that I hadn’t put a semi-colon right after the ball class… Err.

I forgot to put the semi-colon for the ‘ball’ class…



I thought I commented that out…

THANKS!!! >_<

*After Argument*P1: What was it about?P2: Something involving a chair, a cat, and a rubber ducky…

Понравилась статья? Поделить с друзьями:
  • Error multiple storage classes in declaration specifiers
  • Error multiple primary keys for table are not allowed
  • Error multiple accounts are not allowed
  • Error multipart boundary not found
  • Error multilib version problems found