#include<iostream>
using namespace std;

class point{
    private:
        double x,y;
    public:
        double getX();
        double getY();
        void set(double c, double d);
};

class polygon{
    private:
        string color;
    public:
        void setc(string color1){
            color = color1;
        }
        void print(){
            cout<<color;
        }
        string getColor(){
            return color;
        }
};

class triangle: public polygon{
    private:
        point v1,v2,v3;
    public:
        void set(point o, point t, point th){
            v1.set(o.getX(),o.getY());
            v2.set(t.getX(),t.getY());
            v3.set(th.getX(),th.getY());
        }
};


int main(){
    point a,b,c;
    triangle t;
    a.set(1.2,3.4);
    b.set(234.4,543.23);
    c.set(34,31);
    t.set(a,b,c);
    t.setc('red');

}
double point::getX(){
    return x;
}
double point::getY(){
    return y;
}

void point::set(double c, double d){
    x = c;
    y=d;
}

We were learning c++ derivatives yesterday and the professor came up with an example (off the top of his head which is why it doesn't make perfect sense to do it this way). He wanted us to set the color of the triangle using polygon where triangle is a devative function of polygon. My compiler is giving me an error message.

f\Desktop\C++\polygon.cpp|47|warning: multi-character character constant|
\Desktop\C++\polygon.cpp||In function `int main()':|
\Desktop\C++\polygon.cpp|47|error: invalid conversion from `int' to `const char*'|
\Desktop\C++\polygon.cpp|47|error: initializing argument 1 of `std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'|
||=== Build finished: 2 errors, 1 warnings ===|

Any help would be appreciated....

Recommended Answers

All 2 Replies

Line 47, you are attempting to pass " 'red' " to polygon::setc(). The single quotes cause literals to be interpreted as characters. To make the compiler interpret it as a string, you need to use double quotes. i.e. " "red" "

Wow! thanks. I can't believe I hadn't tried that....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.