Hello,

When I compile the following code I get this single error:

In constructor `Point::Point expected `{' before ':' token ()':

I cannot figure out what is wrong. What am I missing? Thanks.

Header file

#include <iostream>
using std::cout;
using std::endl;
 
class Point
{
    friend void setX( Point &, int ); 
    friend void setY( Point &, int ); 
  public:  
    Point() 
      : xCoordinate( 0 )   
      : yCoordinate( 0 ) 
    {
 
    }
    void print() 
    {
      cout << "( " << xCoordinate << "," << yCoordinate << " )" << endl;
    }   
  private:
    int xCoordinate;
    int yCoordinate;
};

Main program

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
 
#include "point.h" 
 
void setX( Point &p, int value )
{
  p.xCoordinate = value;
}
void setY( Point &p, int value )
{
  p.yCoordinate = value;
}
 
int main()
{
  int xCoord, yCoord;
  Point coordinatePlane; 
 
  cout << "A coordinate plane is formed by a horizontal axis and a vertical \n"
       << "axis often labeled the x-axis and y-axis, respectively. \n\n" << endl;
 
  cout << "Enter the x-axis: ";
  cin >> xCoord;
  setX( coordinatePlane, xCoord );
 
  cout << "\n\nEnter the y-axis: ";
  cin >> yCoord;
  setX( coordinatePlane, yCoord );
 
  coordinatePlane.print();
 
  return 0;
}

Your syntax for initializers is incorrect. Use only one colon, then separate with commas.

class Point
{
    friend void setX( Point &, int ); 
    friend void setY( Point &, int ); 
  public:  
    Point() 
      : xCoordinate( 0 ), yCoordinate( 0 ) 
    {
 
    }

Rashakil Fol,

First, thanks for the fast response!

Second, I should have known it was something simple. I assume that there is no limit to the number of initilizers as done in this method?

Thanks again...

Jaden403

Yes, that is what you're assuming :)

And yes, there is no limit to the number of initializers. (Hopefully you don't use more initializers than you have variables... :))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.