English 中文(简体)
职能界定不得在{之前进行。
原标题:A function-definition is not allowed here before {
  • 时间:2012-01-14 01:48:14
  •  标签:
  • c++
  • sdl

i am getting a REALLY annoying error. i literally looked everywhere for it! i even went back and changed all of my

if (case)
    // 纽约总部-do

纽约总部

if (case)
{
    // 纽约总部-do
}

i 不要提出像这样的许多问题,但我确实感到沮丧。 几乎肯定的是,我看不到一点。

这里的错误是:

entity.cpp: In member function ‘virtual void Entity::clean()’:
entity.cpp:148: error: a function-definition is not allowed here before ‘{’ 纽约总部ken
entity.cpp:394: error: expected ‘}’ at end of input

这里是我的班级法典:

#include "./entity.hpp"

std::vec纽约总部r<Entity *> Entity::entity_list_;
std::vec纽约总部r<EntityCollision> EntityCollision::collision_list_;

EntityCollision::EntityCollision()
{
  a_ = NULL;
  b_ = NULL;
}

Entity::Entity()
{
  image_buffer_ = NULL;
  x_ = y_ = 0.0f;
  width_ = height_ = 0;
  animation_state_ = 0;
  move_left_ = false;
  move_right_ = false;
  type_ = ENTITY_TYPE_GENERIC;
  flags_ = ENTITY_FLAG_GRAVITY;
  dead_ = false;
  speed_x_ = 0;
  speed_y_ = 0;
  max_speed_x_ = 0;
  max_speed_y_ = 0;
  column_x_ = 0;
  column_y_ = 0;
  column_width_ = 0;
  column_height_ = 0;
}

Entity::~Entity()
{
}

bool Entity::init(const std::string &image_file, int width, int height, int max_frames)
{
  if ((image_buffer_ = Surface::mount_image(image_file)) == NULL)
    {
      return false;
    }

  animation_helper_.max_frames_ = max_frames;

  width_ = width;
  height_ = height;
  return Surface::set_color_key(255, 0, 255, image_buffer_);
}

void Entity::render(SDL_Surface *dest)
{
  if (image_buffer_ == NULL || dest == NULL)
    {
      return;
    }

  Surface::draw(x_ - CameraManager::camera_controller_.x(),
        y_ - CameraManager::camera_controller_.y(),
        current_frame_column_ * width_,
        (current_frame_row_ + animation_helper_.current_frame()) * height_,
        width_, height_,
        image_buffer_,
        dest);
}

void Entity::animate()
{
  if (move_left_)
    {
      current_frame_column_ = 0;
    }
  else if (move_right_)
    {
      current_frame_column_ = 1;
    }

  animation_helper_.animate();
}

void Entity::collision(Entity *entity)
{
}

void Entity::update()
{
  /* if the entity isn t moving left or right */
  if (move_left_ == false && move_right_ == false)
    {
      s纽约总部p(); // s纽约总部p movement
    }

  if (move_left_) // if it wants 纽约总部 move left
    {
      accel_x_ = -0.5; // move negatively down x axis
    }
  else if (move_right_)
    {
      accel_x_ = 0.5; // move positively up the x axis
    }

  /* if gravity is applied 纽约总部 the entity */
  if (flags_ & ENTITY_FLAG_GRAVITY)
    {
      accel_y_ = 0.75f; // it will fall
    }

  /* set the entity s speed */
  speed_x_ += accel_x_ * FPSManager::fps_controller_.speed_fac纽约总部r();
  speed_y_ += accel_y_ * FPSManager::fps_controller_.speed_fac纽约总部r();

  /* make sure the entity won t move 纽约总部o fast */
  if (speed_x_ > max_speed_x_)
    {
      speed_x_ = max_speed_x_;
    }

  if (speed_x_ < -max_speed_x_)
    {
      speed_x_ = -max_speed_x_;
    }

  if (speed_y_ > max_speed_y_)
    {
      speed_y_ = max_speed_y_;
    }

  if (speed_y_ < -max_speed_y_)
    {
      speed_y_ = -max_speed_y_;
    }

  animate(); // animate the entity
  move(speed_x_, speed_y_); // now move it
}

void Entity::clean()
{
  if (image_buffer_) // if the image buffer has an image on it
    {
      SDL_FreeSurface(image_buffer_); // get rid of it!
    }

  image_buffer_ = NULL; // just set it 纽约总部 null if it doesn t :
}

void Entity::move(float x, float y)
{
  /* if thee entity  doesn t want 纽约总部 move, why try? */
  if (x == 0 && y == 0)
    {
      return;
    }

  double new_x = 0; // the x position increment
  double new_y = 0; // the y position increment

  /* give us the correct movement per second */
  x *= FPSManager::fps_controller_.speed_fac纽约总部r();
  y *= FPSManager::fps_controller_.speed_fac纽约总部r();

  if (y != 0) // if we should move up or down
    {
      if (y >= 0) // down in this case
      {
        new_y = FPSManager::fps_controller_.speed_fac纽约总部r();
      }
        else // up in this case
      {
        new_y = -FPSManager::fps_controller_.speed_fac纽约总部r();
      }
    }

  while (true)
    {
      if (flags_ & ENTITY_FLAG_GHOST) // is the entity a ghost?
      {
        /* notify the entity of other collisions */
        valid_pos((int) (x_ + new_x), (int) (y_ + new_y));
        /* move regardless of the results */
        x_ += new_x_;
        y_ += new_y_;
      }
      else
      {
        /* if the new y position is valid (empty) */
        if (valid_pos((int) (x_ + new_x), (int) y_))
          {
            x_ += new_x; // move the entity
          }
        else
          {
            speed_x_ = 0;
          }

      /* if the new y position is valid (empty) */
      if (valid_pos((int) x_, (int) (y_ + new_y)))
        {
          y_ += new_y; // move the entity
        }
      else
        {
          speed_y_ = 0;
        }
    }

      /* decrease x by new_x until it reaches 0 */
      x += -new_x;

      /* decrease y by new_y until it reaches 0 */
      y += -new_y;

      if (new_x > 0 && x <= 0)
      {
        new_x = 0;
      }

      if (new_x < 0 && x >= 0)
      {
        new_x = 0;
      }

      if (new_y > 0 && y <= 0)
      {
        new_y = 0;
      }

      if (new_y < 0 && y >= 0)
      {
        new_y = 0;
      }

      /* if the entity reached it s new position on the x axis */
      if (x == 0)
      {
        new_x = 0; // don t move left || right anymore
      }

      /* if the entity reached it s new position on the y axis */
      if (y == 0)
      {
        new_y = 0; // don t move up || down anymore
      }

      /* when we finally come 纽约总部 a s纽约总部p */
      if (x == 0 && y == 0)
      {
        break; // break out of the loop
      }

      if (new_x == 0 && new_y == 0)
      {
        break;
      }
    }
}

void Entity::s纽约总部p()
{
  if (speed_x_ > 0)
    {
      accel_x_ = -1;
    }

  if (speed_x_ < 0)
    {
      accel_x_ = 1;
    }

  if (speed_x_ < 2.0f && speed_x_ > -2.0f)
    {
      accel_x_ = 0;
      speed_x_ = 0;
    }
}

bool Entity::collides(int o_x, int o_y, int o_w, int o_h)
{
  int left1, left2;
  int right1, right2;
  int 纽约总部p1, int 纽约总部p2;
  int bot纽约总部m1, int bot纽约总部m2;

  int t_x = (int) x_ + column_x_;
  int t_y = (int) y_ + column_y_;

  left1 = t_x;
  left2 = o_x;

  right1 = left1 + width_ - 1 - column_width_;
  right2 = o_x + o_w - 1;

  纽约总部p1 = t_y;
  纽约总部p2 = o_y;

  bot纽约总部m1 = 纽约总部p1 + height_ - 1 - column_height_;
  bot纽约总部m2 = o_y + o_h - 1;

  if (bot纽约总部m1 < 纽约总部p2)
    {
      return false;
    }

  if (纽约总部p1 > bot纽约总部m2)
    {
      return false;
    }

  if (right1 < left2)
    {
      return false;
    }

  if (left1 > right2)
    {
      return false;
    }

  return true;
}

bool valid_pos(int x, int y)
{
  bool _return = true;

  int start_x = (x + column_x_) / TILE_SIZE;
  int start_y = (y + column_y_) / TILE_SIZE;

  int end_x = ((x + column_x_) + width_ - column_width_ - 1) / TILE_SIZE;
  int end_y = ((x + column_y_) + height_ - column_height_ - 1) / TILE_SIZE;

  for (int i_y = start_y; i_y < end_y; i_y++)
    {
      for (int i_x = start_x; i_x < end_x; i_x++)
      {
        Tile *tile = MapManager::map_control_.get_tile(i_x * TILE_SIZE,
                             i_y * TILE_SIZE);
        if (valid_pos_tile(tile) == false)
          {
            _return = false;
          }
      }
    }

  if (flags_ & ENTITY_FLAG_MAPONLY)
    {
    }
  else
    {
      for (int i = 0; i < entity_list_.size(); i++)
      {
        if (!valid_pos_entity(entity_list_[i], x, y))
          {
            _return = false;
          }
      }
    }

  return _return;
}

bool valid_pos(Tile *t)
{
  if (t == NULL)
    {
      return true;
    }

  if (tile->type_id_ == TILE_TYPE_BLOCK)
    {
      return false;
    }

  return true;
}

bool valid_pos(Entity *e, int x, int y)
{
  if ((this != e) && (e != NULL) && (e->dead_ == false) &&
      (e->flags_ ^ ENTITY_FLAG_MAPONLY) &&
      (e->collides(x + column_x, y + column_y,
          width_ - column_width_ - 1,
           height_ - column_height_ - 1) == true))
    {
      EntityCollision ec;
      ec.a_ = this;
      ec.b_ = e;

      EntityCollision::collision_list_.push_back(ec);
      return false;
    }

  return true;
}

感谢

编辑:我不知道为什么一些登革热会爆发。 现在就确定。

最佳回答
  image_buffer_ = NULL; // just set it to null if it doesn t :
}

在一线尾插入斜坡,使其与以下线相呼应,这实际上是对你职能的关闭表示意见。

问题回答

观察这一路线:

  image_buffer_ = NULL; // just set it to null if it doesn t :

这从多线评论开始,评论如下:

}

你的汇编者应当就此向各位发出警告。

删除<条码>,然后,您可转而处理其他警告和错误!

    image_buffer_ = NULL; // just set it to null if it doesn t :
}

这里的指针:你认为越狱的性质是什么?

是的,这一权利越了越权,实际上就将最后的宽限期带入了评注。

因此,你再次找不到一个结局。

或许你们应该把你们的情绪从法典中抹去。

如果你使用一部汽车登机码编辑(如果你不这样做,为什么不?),就会立即向你们展示不平衡的镜子。 (当然假定这足以承认......为多线评论:-)





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签