Sign in to follow this  
c4c0d3m0n

error: expected initializer before 'foo'

Recommended Posts

I'm baffled.. I've tried googling, but this error message seems too generic for any good answers from there. My code: field.h
#ifndef _TTT_FIELD_H_
#define _TTT_FIELD_H_

#include <vector>



namespace ttt
{


enum symbol { empty = 0, x = 1, o = 2 };
enum coord { one = 0, two = 1, three = 2 };


class Field
{
  public:

    Field();

    void clear();

    symbol get( coord, coord ) const;
    void   set( coord, coord, symbol );


  private:

    std::vector<symbol> m_field;

}; // class Field


} // namespace ttt



#endif // _TTT_FIELD_H_
field.cpp
#include "field.h"

#include <vector>



ttt::Field::
Field()
    : m_field ( 9, empty )
{
}



void
ttt::Field::
clear()
{
    for ( int i = 0; i < 9; ++i )
      m_field[i] = empty;
}



ttt::symbol
ttt::Field
get( ttt::coord x, ttt::coord y ) const
{
    return m_field[x+3*y];
}


void
ttt::Field
set( ttt::coord x, ttt::coord y, ttt::symbol s )
{
    m_field[x+3*y] = s;
}
The errors
field.cpp:25: error: expected initializer before ‘get’
field.cpp:33: error: expected initializer before ‘set’

Share this post


Link to post
Share on other sites

void
ttt::Field::set( ttt::coord x, ttt::coord y, ttt::symbol s )
{
m_field[x+3*y] = s;
}

same goes for the get.

Regards.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this