Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6606589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:24:43+00:00 2026-05-25T19:24:43+00:00

I am trying to implement a player class, so I created two files in

  • 0

I am trying to implement a player class, so I created two files in my threads folder,
player.cc and player.h

player.h goes like this :

#ifndef PLAYER_H
#define PLAYER_H
#include "utility.h"

class Player()
{
  public:
   //getPlayerID();
};

#endif

then player.cc goes like

#include "player.h"

class Player()
{
  string playerID;
  int timeCycle;
}

Then in my main.cc and threadtest.cc , I add in #include player.h and then I start to errors and it fails to compile. I am new to nachos and a little bit unfamiliar with c++, so I am confused as to how to resolve this problem. Nachos does not provide a solution through the compiler either.

When I type gmake, it says two things for errors.
1. parse error before ‘(‘ in player.h (referring to Player())
2. * [main.o] Error 1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:24:44+00:00Added an answer on May 25, 2026 at 7:24 pm

    Let’s go through line-by-line:

    #ifndef PLAYER_H
    #define PLAYER_H
    #include "utility.h"
    

    So far so good, you might check if your compiler supports #pragma once, but the macro will work perfectly fine.

    class Player()
    

    () aren’t allowed in a class name, take them off

    {
      public:
       //getPlayerID();
    };
    
    #endif
    

    The rest of the header file is ok. Let’s look at the implementation file:

    #include "player.h"
    

    Perfect. Putting a class in a header is the best way to make sure you only have one definition used in your whole program.

    class Player()
    

    Parentheses aren’t allowed, but here you have a bigger problem. You already have a class with that name. Let the header provide the class definition, the implementation file just needs to provide the non-inline member functions (and any helper code).

    {
      string playerID;
      int timeCycle;
    }
    

    Here’s a complete corrected version:

    #if !defined(PLAYER_H)
    #define PLAYER_H
    
    #include <string>
    #include "utility.h"
    
    class Player
    {
         std::string player_id;
         int time_cycle;
    
    public:
         // this is how you make a constructor, the parenthesis belong here, not on the class name
         Player(std::string id, int time);
    
         std::string getPlayerId() const;
    };
    
    #endif /* !defined(PLAYER_H) */
    

    and implementation file

    #include "player.h"
    
    // and this is how you write a non-inline constructor
    Player::Player(std::string id, int time)
        : player_id(id)
        , time_cycle(time)
    {}
    
    std::string Player::getPlayerId() const
    {
        return player_id;
    }
    

    All of these problems are really basic C++ stuff, nothing to do with NachOS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement the Media Player custom field control described in this MSDN
I'm trying to implement something like this: <div> <table> <thead> <tr> <td>Port name</td> <td>Current
I am trying to implement a Flash YouTube video player on this page .
I have this Player class which implements the Comparable interface. Then I have an
Im trying to implement fade in effect to my mp3 player. I´m using FloatControl
I'm trying to build/implement a Flash video player to play videos. I have looked
I'm trying to implement a Java/C++ binding for a sound streaming class. To keep
I have been trying this for so long, but was not able to implement
I'm trying to implement a countdown timer into a pre-existing public class and I
All I am currently trying implement something along the lines of dim l_stuff as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.