File: class.cpp

package info (click to toggle)
libpulp 0.3.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,976 kB
  • sloc: ansic: 11,792; python: 1,216; sh: 881; makefile: 871; cpp: 582; asm: 387
file content (48 lines) | stat: -rw-r--r-- 649 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <unistd.h>
#include <math.h>

#define noinline __attribute__((noinline))

class Point
{
  private:
  void noinline Print(double n);

  protected:
  double x, y;

  public:
  Point(double x, double y);
  double Norm(void);
};

Point::Point(double x, double y)
{
  this->x = x;
  this->y = y;
}

// Will be livepatched;
double Point::Norm(void)
{
  double n = sqrt(x*x + y*y);
  Print(n);
  return n;
}

void noinline Point::Print(double n)
{
  std::cout << "Point: " << x << ' ' << y << ' ' << "Have norm2 = " << n <<'\n';
}

int main(void)
{
  Point p(3, 4);
  while (1) {
    p.Norm();
    sleep(1);
  }

  return 0;
}