Hello members of stack overflow! I am hoping someone who has been where I am can point me in the right direction.
I am currently learning C++ and working on the graphics exercises found in chapter 12 but I cannot seem to get code that should work to work. I have been attempting for days to get any code to work and have overcome some big problems already but since I am only learning C++, I am at this point at the limit of my expertise and have exhausted all previously asked questions on various forums which actually solved a lot of other problems I was having.
Here is the simple graphics code and below that the large amount of error messages I receive:
//
// This is example code from Chapter 12.3 "A first example" of
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//
#include <PPP2HEADERS/Simple_window.h>// get access to our window library
#include <PPP2HEADERS/Graph.h>// get access to our graphics library facilities
//------------------------------------------------------------------------------
int main()
{
using namespace Graph_lib; // our graphics facilities are in Graph_lib
Point tl(100, 100); // to become top left corner of window
Simple_window win(tl, 600, 400, "Canvas"); // make a simple window
Graph_lib::Polygon poly; // make a shape (a polygon)
poly.add(Point(300, 200)); // add a point
poly.add(Point(350, 100)); // add another point
poly.add(Point(400, 200)); // add a third point
poly.set_color(Color::red); // adjust properties of poly
win.attach(poly); // connect poly to the window
win.wait_for_button(); // give control to the display engine
}
//------------------------------------------------------------------------------
error messages received when attempting to compile:
1>------ Build started: Project: test2, Configuration: Debug Win32 ------
1>test4.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\VS\include\PPP2HEADERS\Graph.h(45,10): warning C4305: 'initializing': truncation from 'Graph_lib::Color::Transparency' to 'char'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\VS\include\PPP2HEADERS\Graph.h(45,46): warning C4309: 'initializing': truncation of constant value
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\VS\include\PPP2HEADERS\Graph.h(47,10): warning C4305: 'initializing': truncation from 'Graph_lib::Color::Transparency' to 'char'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\VS\include\PPP2HEADERS\Graph.h(47,39): warning C4309: 'initializing': truncation of constant value
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\VS\include\PPP2HEADERS\GUI.h(107,39): warning C4018: '<': signed/unsigned mismatch
1>C:\Users\darai\Documents\PPP C++ CODE\chapter12_graphics_example\test2\test4.cpp(16,23): error C2440: 'initializing': cannot convert from 'initializer list' to 'Graph_lib::Point'
1>C:\Users\darai\Documents\PPP C++ CODE\chapter12_graphics_example\test2\test4.cpp(16,23): message : No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\Users\darai\Documents\PPP C++ CODE\chapter12_graphics_example\test2\test4.cpp(22,28): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'
1>C:\Users\darai\Documents\PPP C++ CODE\chapter12_graphics_example\test2\test4.cpp(22,28): message : No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\Users\darai\Documents\PPP C++ CODE\chapter12_graphics_example\test2\test4.cpp(23,28): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'
1>C:\Users\darai\Documents\PPP C++ CODE\chapter12_graphics_example\test2\test4.cpp(23,28): message : No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\Users\darai\Documents\PPP C++ CODE\chapter12_graphics_example\test2\test4.cpp(24,28): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'Graph_lib::Point'
1>C:\Users\darai\Documents\PPP C++ CODE\chapter12_graphics_example\test2\test4.cpp(24,28): message : No constructor could take the source type, or constructor overload resolution was ambiguous
1>Done building project "test2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I am pretty sure FLTK is installed correctly as there is an example code found in appendix D of the book which does compile and I am also using the updated headers as mentioned here.
At this point i have been attempting to get graphics code to work for days and I am wondering if learning the graphics portion of the book is absolutely necessary.
Any help anyone can provide would be hugely appreciated and apologies if I have broken any rules, this is my first time posting to stack overflow.
Thank you.
Point.H as requested:
//
// This is a GUI support code to the chapters 12-16 of the book
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//
#ifndef POINT_GUARD
#define POINT_GUARD
namespace Graph_lib {
//------------------------------------------------------------------------------
struct Point {
int x, y;
};
//------------------------------------------------------------------------------
inline bool operator==(Point a, Point b) { return a.x==b.x && a.y==b.y; }
//------------------------------------------------------------------------------
inline bool operator!=(Point a, Point b) { return !(a==b); }
//------------------------------------------------------------------------------
}
#endif // POINT_GUARD