C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 15th, 2012, 09:08 AM
yanni yanni is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 yanni User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #2  
Old November 15th, 2012, 12:12 PM
ediz ediz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 102 ediz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 35 m 33 sec
Reputation Power: 3
Point2D.h:12: error: ‘int Point2D::x’ is protected

It seems like in the class Point2D
you have encapsulated x and y with protected.
You cannot access protected data members outside the class, unless if they are inherited.
You can only access them by using public.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Classes - Classes compilation error, please advise


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap