0

i made a class as A2dd and i want an output by printf from gx+gy but i dont see as the output. i want that the output which is from the class be shown in the console (since i use eclispe). but i just see "hello world".

where is the problem?

Main:

#include <iostream>
#include <stdio.h>
#include "A2dd.h"

using namespace std;

int main( )
{
A2dd(5,2);
int getsum();
cout << "hello world" << endl;

return 0;
}

header:

#ifndef A2DD_H_
#define A2DD_H_

class A2dd {

public:
int gx;
int gy;
A2dd(int x, int y);
int getsum();

};

#endif /* A2DD_H_ */

A2dd:

#include <stdio.h>
#include "A2dd.h"
using namespace std;

A2dd::A2dd(int x, int y)
{
gx = x;
gy = y;
}

int A2dd::getsum()
{
 printf ("%d" , gx + gy);
 return 0;
}
Mason
  • 29
  • 1
  • 7

1 Answers1

2

A2dd(5,2); constructs an unnamed object of type A2dd and immediately destroys it. int getsum(); declares but does not define a function named getsum that takes no arguments and returns int. Neither of those is what you want to do. Instead, try this:

A2dd value(5,2);
value.getsum();
Pete Becker
  • 72,338
  • 6
  • 72
  • 157