mardi 3 mai 2016

Visual Studio 2015 Error C3867 'Rectangle::get_area': non-standard syntax; use '&' to create a pointer to member

I am having difficulty understanding why I get this error in the context of my simple program using a user defined class "Rectangle"

The Rectangle class I made is used to create rectangles by inputting length/width, then printing l/w/area.

I have looked in these locations so far in an attempt to understand the issue, and still can not understand the problem. http://ift.tt/26RwBdD

Visual Studio 2015 "non-standard syntax; use '&' to create a pointer to member"

Visual Studio 2015 "non-standard syntax; use '&' to create pointer for member"

(I do not understand what pointers are, I have not learned about them yet in the book Stroustrup: Programming -- Principles and Practice Using C++ 2nd Ed.@ Ch.10)

Here is my Rectangles.h

#include "stdafx.h"
#include <iostream>
using namespace std;

class Rectangle {
public:
    Rectangle();
    Rectangle(double dblp_length, double dblp_width);
    bool is_square() const;
    void set_length(double dblp_length);
    double get_length() const;
    void set_width(double dblp_width);
    double get_width() const;
    void set_area(double dblp_length, double dblp_width);
    double get_area() const;
    void print(ostream & output);


private:
    void Rectangle::init(double dblp_length, double dblp_width);
    double dbl_length, dbl_width, dbl_area;
};

My Rectangle.cpp

#include "stdafx.h"
#include "Rectangle.h"
#include <iostream>


Rectangle::Rectangle() {
    init(8, 8);
}

Rectangle::Rectangle(double dblp_length, double dblp_width) {
    init(dblp_length, dblp_width);
}

void Rectangle::init(double dblp_length, double dblp_width) {
    set_length(dblp_length);
    set_width(dblp_width);
}

void Rectangle::set_length(double dblp_length) {
    if (dblp_length < 0 || dblp_length > 1024) {
        dblp_length = 8;
    }
        double dbl_length = dblp_length;
}

double Rectangle::get_length() const {
    return dbl_length;
}

void Rectangle::set_width(double dblp_width) {
     if (dblp_width < 0 || dblp_width > 1024) {
        dblp_width = 8;
    }
        double dbl_width = dblp_width;
}

double Rectangle::get_width() const {
    return dbl_width;
}

bool Rectangle::is_square() const {
    if (get_length() == get_width()) {
        return true;
    }
}

void Rectangle::set_area(double dblp_length, double dblp_width) {
    double dbl_area;
    dbl_area = (dblp_length * dblp_width);
}

double Rectangle::get_area() const {
    return dbl_area;
}

void Rectangle::print(ostream & output) {
    output << "Length: " << get_length() << ", " <<
        "Width :" << get_width() << ", " <<
        "Area: " << get_area << endl;
}

Aucun commentaire:

Enregistrer un commentaire