
November 15th, 2012, 08:08 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 1
Time spent in forums: 12 m 11 sec
Reputation Power: 0
|
|
|
Classes - Classes compilation error, please advise
=============
Line2D.h
=============
#include <iostream>
#include <string>
#include <fstream>
#include <math.h>
#include "Point2D.h"
using namespace std;
class Line2D
{
private:
Point2D pt1;
Point2D pt2;
protected:
double length;
void setLength();
public:
Line2D(Point2D, Point2D);
Point2D getPt1();
Point2D getPt2();
double getScalarValue();
void setPt1(Point2D);
void setPt2(Point2D);
int getX();
int getY();
void setX(int);
void setY(int);
};
=============
Line2D.cpp
=============
#include "Line2D.h"
//#include "Point2D.h"
using namespace std;
Line2D::Line2D(Point2D point1, Point2D point2) : pt1(point1),pt2(point2)
{
pt1 = point1;
pt2 = point2;
}
Point2D Line2D::getPt1()
{
return pt1;
}
Point2D Line2D::getPt2()
{
return pt2;
}
double Line2D::getScalarValue()
{
return length;
}
void Line2D::setPt1(Point2D PT1)
{
pt1 = PT1;
}
void Line2D::setPt2(Point2D PT2)
{
pt2 = PT2;
}
void Line2D::setLength()
{
length = sqrt (pow(pt1.x - pt2.x),2) + pow(pt1.y - pt2.y),2);
}
=============
Error messages
=============
Point2D.h: In member function ‘void Line2D::setLength()’:
Point2D.h:12: error: ‘int Point2D::x’ is protected
Line2D.cpp:40: error: within this context
Point2D.h:12: error: ‘int Point2D::x’ is protected
Line2D.cpp:40: error: within this context
/usr/include/bits/mathcalls.h:154: error: too few arguments to function ‘double pow(double, double)’
Line2D.cpp:40: error: at this point in file
Point2D.h:13: error: ‘int Point2D::y’ is protected
Line2D.cpp:40: error: within this context
Point2D.h:13: error: ‘int Point2D::y’ is protected
Line2D.cpp:40: error: within this context
/usr/include/bits/mathcalls.h:154: error: too few arguments to function ‘double pow(double, double)’
Line2D.cpp:40: error: at this point in file
Line2D.cpp:40: error: expected ‘;’ before ‘)’ token
I'm really a beginner in C++, desperately in need of assistance . Can any kind soul assist? How can I code to access protected data from another class?
And what is wrong with the formula?
|