"point" class questions

Hello!
Please, if we have point.h file, like this one:

1
2
3
4
5
6
7
8
9
10
11
  // point.h

class point {
  private:
    int x, y;
  public:
    void init(int x1, int y1);
    int getX();
    int getY();
    void print();
};


and program like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// point.cpp
#include <iostream>
#include "point.h"

using namespace std;

void point::init(int x1, int y1) {
  x = x1;
  y = y1;
}

int point::getX() {
  return x;
}

int point::getY() {
  return y;
}

void point::print() {
  cout << "(" << x << "," << y << ")" << endl;
}


please, where do we define (initialise) x1 and y1?
MANY thanks!!!
Last edited on
It is normally done in the main programme file.
-Create the main file eg: main.cpp
-Include the "point.h" header
-Then in your main function, you can create an object and call the initialize[1] method, passing the integers as arguments.

[1] It is advisable to do the initializing in the constructor.

Aceix.
Topic archived. No new replies allowed.