illegal operation on bound member function expression

Y

yogi_bear_79

I am working on a lab with my first exposure to classes. With help
from this group I have completed my point class, and now I am working
on this one, this is what I have so far, but I am running into the
subject error, on my getSlope function. I am very much a beginner,
distant-learning self taught, and a system admin, not a programmer by
trade,

#include<iostream>

#ifndef h_Line
#define h_Line

#include "Point.h"

class Line
{
Point a, b;
public:
Line(const Point& a, const Point& b);
double getSlope(const Point& a, const Point& b);
};

inline Line::Line(const Point& a, const Point& b){}

inline double Line::getSlope(const Point& a, const Point& b)
{
return (&b.getY - &a.getY)/(&b.getX - &a.getX);
}

#endif
 
I

Ian Collins

yogi_bear_79 said:
I am working on a lab with my first exposure to classes. With help
from this group I have completed my point class, and now I am working
on this one, this is what I have so far, but I am running into the
subject error, on my getSlope function. I am very much a beginner,
distant-learning self taught, and a system admin, not a programmer by
trade,

#include<iostream>

#ifndef h_Line
#define h_Line

#include "Point.h"

class Line
{
Point a, b;
public:
Line(const Point& a, const Point& b);
double getSlope(const Point& a, const Point& b);

This function is working on two points, so it may as well be declared
static.
};

inline Line::Line(const Point& a, const Point& b){}

inline double Line::getSlope(const Point& a, const Point& b)
{
return (&b.getY - &a.getY)/(&b.getX - &a.getX);

These are functions, getY(). Why are you taking their addresses?

See why I suggested ditching the accessors? Wouldn't it be clearer to
write.

return (b.myY - a.myY)/(b.myX - a.myX);
 
Y

yogi_bear_79

See why I suggested ditching the accessors?  Wouldn't it be clearer to
write.


OK, took your advice on the point class, reworked this class (work in
progress) I have about 10 compile errors to look at:

#include<iostream>

#ifndef h_Line
#define h_Line

#include "Point.h"

class Line
{
Point a, b;
public:
Line(const Point a, const Point b);
static slope(const Point a, const Point b);
double slopeIntercept(double m, const Point a, const Point b);
private:
double m;
};

inline Line::Line(const Point& a, const Point& b){}

inline void Line::slope(const Point a, const Point b)
{
m =(b.myY - a.myY)/(b.myX - a.myX);
}

#endif
 
R

Richard Herring

In message
OK, took your advice on the point class, reworked this class (work in
progress) I have about 10 compile errors to look at:

#include<iostream>

#ifndef h_Line
#define h_Line

#include "Point.h"
class Line

Start by adding some comments explaining what this class is supposed to
represent.
{
Point a, b;
public:
Line(const Point a, const Point b);

And a comment explaining what the constructor does with these Points,
and why.
static slope(const Point a, const Point b);

And a comment explaining what this function does, and why it needs to be
a member of the class at all when it apparently doesn't access any
instance of the class.
BTW what's its return type?
double slopeIntercept(double m, const Point a, const Point b);

And a comment explaining what the arguments to this function represent,
what it does with them, what it returns, and why it's a member of the
class (does it access any data specific to an instance of the class?)
double m;

And what this member variable represents.

By the time you've written all those comments, you should have a much
clearer idea of what you are trying to achieve, and why the compiler is
objecting. Once that's clear, you can turn your attention to the
following:
inline Line::Line(const Point& a, const Point& b){}

Inconsistent with the declaration above (are you passing by value or
const reference? why are you passing parameters that never get used,
anyway?)
inline void Line::slope(const Point a, const Point b)

void? Shouldn't a function called slope() return something representing
a slope?
{
m =(b.myY - a.myY)/(b.myX - a.myX);

What's this 'm'? This is a static function, so it can't be a member
variable.

Where's the definition of slopeIntercept() ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top