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 6564457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:58:08+00:00 2026-05-25T13:58:08+00:00

Just learning Classes in C++, I thought I had a fairly good grip on

  • 0

Just learning Classes in C++, I thought I had a fairly good grip on it but for some reason this code won’t even compile.

#include <iostream>
#include <cstdlib>

using namespace std;

class Position
{
    int row;
    int column;
public:
    Position();         //constructor
    ~Position();        //destructor
    void setPos(int, int);  //set the position
    int getRow();       //return the current row
    int getColumn();    //return the current column
    void getPos();      //print the pos
    bool compare(int, int); //compare a row and column with the one in the class
};

Position::Position()
{}
Position::~Position()
{}
void Position::setPos(int x, int y)
{
    Position.row = x;
    Position.column = y;
}
int Position::getRow()
{
    return Position.row;
}
int Position::getColumn()
{
    return Position.column;
}
void Position::getPos()
{
    cout << "Row: " << Position.row << "Column: " << Position.column;
}
bool Position::compare(int x, int y)
{
    if(x == Position.row && y == Position.column)
        return true;
    else
        return false;
}

Running this code straight in MS Visual Studio 2010 yields these compiling problems:

...prob2.cpp(30): error C2143: syntax error : missing ';' before '.'
Line 30 is: Position.row = x;
I don’t see why or where there should be a ; anywhere there.

I get this error on several other lines including the one right under it.

I should note that I don’t have a main function although I don’t think this is needed.

  • 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-25T13:58:09+00:00Added an answer on May 25, 2026 at 1:58 pm

    You don’t need to prefix instance variables using the class name, instead use row or this->row

    EDIT:

    Eventually you will want to move the class declaration to a header file ie. position.h and keep the implementation in the position.cpp file with #include "position.h" at the top. This will make your Position class usable in other files.

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

Sidebar

Related Questions

I just started learning classes in C++ and I get this error for the
Hey guys, just learning about composition of classes and ran into this error. Gradebook.h
I'm just learning to work with partial classes in VB.NET and VS2008. Specifically, I'm
I'm just learning about SVG, and it seems great but I'm not sure about
I'm just learning how to do things, and want to start using some sort
Hello I am just learning more about using classes in PHP. I know the
I am just learning how to use classes in my projects. I have been
Just started learning PySide and is having problem with QTimer I have this #!/usr/bin/python
I'm new to NHibernate and not very good at C#, but I'm learning. I
I understand the concept behind DI, but I'm just learning what different IoC containers

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.