No default instructer exists for (inherited class) c++ - c++

Program's purpose: This program's purpose it to create a basic 2d game using only the consol. The program currently only creates a moveable box with the keys "wasd". I'm planning to incorperate bullets, enemy NPC's, barriers, and much more.
Problem:
Hello, for some reason my bullet constructor class in my "Bullet.cpp" file is showing up with the error "error C2512: 'BoxClass': no appropriate default constructor available". In "Bullet.h" I have "class Bullet : protected BoxClass". Why am I getting this error?
Other Question(s):
Also how should I group my headers? They're getting to become a large cluster.
Comments:
I also realize my game loops shouldn't be in the "BoxClass.cpp". I'm going to fix that after I get my bullet class working. If I'm structuring anything else wrong or if you see an easier way of writing some of the same code just let me know.
This is my first graphical game in c++!
ConsolApplication1.cpp:
#include "stdafx.h"
#include <windows.h>
#include "BoxClass.h"
#include "ConsolWindow.h"
#include "Bullet.h"
#include <iostream>
using namespace std;
#define W_KEY 0x57
#define S_KEY 0x53
#define A_KEY 0x41
#define D_KEY 0x44
#define R_KEY 0x52
int main() {
//variable declaration/definition
int right_Wall, speed_Var;
//Consol Size/Position
int half_screen_Size = (GetSystemMetrics(SM_CXSCREEN)/2);
Set_Consol_Size(half_screen_Size, GetSystemMetrics(SM_CYSCREEN));
Position_Consol(-6, 0);
while (1) {
cout << "Enter speed of rectangle/box\nSpeed = ";
cin >> speed_Var;
BoxClass box1(4, 3);
box1.Print_Solid_Rectangle();
cout << "\n\nMove the rectangle with wasd\n\n";
//Rectangle Movement
box1.Rectangle_Movement(speed_Var);
}
//exit
return 0;
}
BoxClass.cpp:
#include "stdafx.h"
#include "BoxClass.h"
#include "ConsolWindow.h"
#include <iostream>
#include <math.h>
#include <Windows.h>
using namespace std;
#define W_KEY 0x57
#define S_KEY 0x53
#define A_KEY 0x41
#define D_KEY 0x44
#define R_KEY 0x52
#define _NOT_MOVING 0
#define _MOVING 1
//Non Moving Rectangle
void BoxClass::Print_Solid_Rectangle() {
//calc
boxSpacesWidth = (3 * recWidth) - 4;
//draw top of box
for (width = 1; width < recWidth; width += 1) {
cout << "...";
}
cout << "\n";
//draw sides
for (height = 1; height < recHeight; height += 1) {
cout << ":";
height_Count++;
for (width = 1; width < boxSpacesWidth; width += 1) {
cout << " ";
}
cout << ":\n";
}
//draw bottom
cout << ":";
for (width = 1; width < boxSpacesWidth; width += 1) {
cout << ".";
}
cout << ":\n";
}
//Moving Rectangle
void BoxClass::Print_Rectangle_Moving(int x, int y, int horizontalSpaces, int verticleSpaces) {
//calc
boxSpacesWidth = (3 * x) - 4;
rightWall = ((x-1)*3) + horizontalSpaces;
retrieveX = (ceil((((x-1)*3)/2))+1)+horizontalSpaces;
retrieveY = verticleSpaces;
cout << retrieveY<<endl;
//New Line
for (i = 1; i <= verticleSpaces; i += 1) {
cout << "\n";
}
//draw top of box
for (width = 1; width <= horizontalSpaces; width+=1) {
cout << " ";
}
for (width = 1; width < x; width += 1) {
cout << "...";
}
cout << "\n";
//draw sides
for (height = 1; height < y; height += 1) {
for (width = 1; width <= horizontalSpaces; width += 1) {
cout << " ";
}
cout << ":";
height_Count++;
for (width = 1; width < boxSpacesWidth; width += 1) {
cout << " ";
}
cout << ":\n";
}
//draw bottom
for (width = 1; width <= horizontalSpaces; width += 1) {
cout << " ";
}
cout << ":";
for (width = 1; width < boxSpacesWidth; width += 1) {
cout << ".";
}
cout << ":\n";
}
void BoxClass::Rectangle_Movement(int speed) {
speed_Var = speed;
//Rectangle Movement
while (GetAsyncKeyState(VK_ESCAPE) == false) {
if (GetAsyncKeyState(R_KEY)) {
system("CLS");
break;
}
if (GetAsyncKeyState(W_KEY)) {
if (verticleCount > 0) {
system("CLS");
verticleCount = verticleCount - speed_Var;
Print_Rectangle_Moving(recWidth, recHeight, horizontalCount, verticleCount);
}
}
if (GetAsyncKeyState(S_KEY)) {
system("CLS");
verticleCount = verticleCount + speed_Var;
Print_Rectangle_Moving(recWidth, recHeight, horizontalCount, verticleCount);
}
if (GetAsyncKeyState(A_KEY)) {
if (horizontalCount > 0) {
system("CLS");
horizontalCount = horizontalCount - (speed_Var*2);
Print_Rectangle_Moving(recWidth, recHeight, horizontalCount, verticleCount);
}
}
if (GetAsyncKeyState(D_KEY)) {
if (rightWall < 113) {
system("CLS");
horizontalCount = horizontalCount + (speed_Var*2);
Print_Rectangle_Moving(recWidth, recHeight, horizontalCount, verticleCount);
}
}
if (GetAsyncKeyState(VK_SPACE)) {
}
}
}
// constructor
BoxClass::BoxClass(int x, int y) {
//variable definition
height_Count = 1;
speed_Var = 1;
horizontalCount = 0;
verticleCount = 0;
recWidth = x;
recHeight = y;
};
BoxClass.h:
#ifndef BOXCLASS_H
#define BOXCLASS_H
class BoxClass {
unsigned short int width;
int height, i, recWidth, recHeight, rightWall;
float boxSpacesWidth, height_Count;
int width_Var, height_Var, position_Var;
int speed_Var = 1;
unsigned short int horizontalCount = 0, verticleCount = 0;
protected:
//retrieve values for bullet spawn location
int retrieveX, retrieveY;
public:
void Print_Rectangle_Moving(int x, int y, int horizontalSpaces, int verticleSpaces);
void Print_Solid_Rectangle();
void Rectangle_Movement(int speed);
// constructor
BoxClass(int x, int y);
};
#endif
Bullet.cpp:
#include "stdafx.h"
#include "Bullet.h"
#include <iostream>
#include <Windows.h>
using namespace std;
void Bullet::Bullet_Draw_Collision() {
for (int height = 1; height <= 2; height+=1) {
cout << "|\n";
}
}
Bullet::Bullet() {
}
Bullet.h:
#ifndef BULLET_H
#define BULLET_H
#include "BoxClass.h"
class Bullet : public BoxClass {
public:
void Bullet_Draw_Collision();
//constructor
Bullet();
};
#endif
ConsolWindow.cpp:
#include "stdafx.h"
#include "ConsolWindow.h"
#include <iostream>
#include <Windows.h>
using namespace std;
int Find_Consol_Size() {
CONSOLE_SCREEN_BUFFER_INFO csbi;
int columns, rows;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
return columns;
}
void Set_Consol_Size(int x, int y) {
HWND console = GetConsoleWindow();
RECT r;
GetWindowRect(console, &r);
MoveWindow(console, r.left, r.top, x, y, TRUE);
}
void Position_Consol(int x, int y) {
HWND consoleWindow = GetConsoleWindow();
SetWindowPos(consoleWindow, 0, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
ConsolWindow.h:
#ifndef CONSOLWINDOW_H
#define CONSOLWINDOW_H
int Find_Consol_Size();
void Set_Consol_Size(int x, int y);
void Position_Consol(int x, int y);
#endif

In c++, constructing a derived type implies that both the base and derived portions of the object must be constructed. This is done by calling the base's constructor before the derived type's constructor can begin.
The default behavior is to use the base's default constructor. However you can indicate a different base constructor to use by adding it to the member initialization list and providing appropriate arguments for it.
In your case, notice that a BoxClass only has one constructor which must be provided with an x and y, but a Bullet has no such construction argument. Perhaps some default values such as zeroes or ones might be appropriate, though I suspect you will want to add those arguments to your Bullet class. Here are a few example to illustrate how you could solve the problem.
By asking for construction arguments for Bullet :
class Bullet : public BoxClass
{
public:
//constructor
Bullet(int x, int y);
};
Bullet::Bullet(int x, int y) :
BoxClass(x, y) // Indicates which BoxClass constructor to use
{}
By providing arbitrary construction arguments to BoxClass :
class Bullet : public BoxClass
{
public:
//constructor
Bullet();
};
Bullet::Bullet() :
BoxClass(1, 1)
{}
Or by adding a default constructor to BoxClass, such as by giving a default value to each of it's existing constructor's arguments :
class BoxClass
{
public:
// This constructor is now a default constructor
BoxClass(int x = 1, int y = 1);
};
class Bullet : public BoxClass
{
public:
//constructor
Bullet();
};
Bullet::Bullet() // Uses the default BoxClass constructor
{}
Which solution is best depends on your design goals, but I suspect the first one is likely to be more appropriate.

Related

Undefined symbols for architecture x86_64: (linker issue?)

I'm doing the following problem :
Add on to your Rectangle class from last time:
1)Create a new class TestRect which is a friend class of Rectangle. Inside this class, implement a member function called TestRect::tester, which takes a rectangle as a parameter and tests that both length and width are > 0.
2)Create a main() function which makes three rectangles r1, r2, and r3, each of which has length and width 20. Then call your TestRect::tester function on each of these rectangles and print out the result
I think I did part 1) correctly but part 2) does not give me the output I'm looking for. I do not know how to fix my code from the following output I got :
cppcompile rectEnhanceStaticFriends
Undefined symbols for architecture x86_64:
"TestRect::tester(Rectangle&)", referenced from:
_main in rectEnhanceStaticFriends.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
cppcompile:15: no such file or directory: ./rectEnhanceStaticFriends
Can you help me how to fix it? Seems a linker issue, that I did not find how to fix it. Thank you for reading through. (Ps: I compile with VSC)
Here is my code :
rectEnhanceStaticFriends.cpp
#include <iomanip>
#include <cstring>
#include <string>
#include "rect.h"
using namespace std;
int main()
{
Rectangle::setYards(100);
Rectangle r1(20, 20, "Kitchen");
Rectangle r2(20, 20, "Bathroom");
Rectangle r3(20, 20, "Office");
TestRect tr;
cout << "Test on r1: " << tr.tester(r1) << endl;
cout << "Test on r2: " << tr.tester(r2) << endl;
cout << "Test on r3: " << tr.tester(r3) << endl;
Rectangle house[] = {Rectangle(10, 12, "Kitchen"),
Rectangle(20, 20, "Bedroom"),
Rectangle(8, 12, "Offce")};
for (int i = 0; i < 3; i++)
{
if (strcmp(house[i].printName(), "Offce") == 0)
{
// cout << "oui\n";
house[i].setName("Office");
};
cout << "Area for " << house[i].printName() << " is : " << house[i].getArea() << endl;
}
if (house[1].getArea() > house[2].getArea() && house[1].getArea() > house[3].getArea())
{
cout << house[1].printName() << " has the biggest area.\n";
}
else if (house[2].getArea() > house[1].getArea() && house[2].getArea() > house[3].getArea())
{
cout << house[2].printName() << " has the biggest area\n";
}
else
{
cout << house[3].printName() << " has the biggest area\n";
}
//there is an error house[3] go beyond the array..
return 0;
}
testRect.h
#ifndef TESTRECT_H
#define TESTRECT_H
class Rectangle; //forward declaration of class Rectangle
class TestRect
{
public:
bool tester(Rectangle &);
};
#endif
testRect.cpp
#include <iostream> //
#include <iomanip>
#include <string>
#include "testRect.h"
#include "rect.h"
bool TestRect::tester(Rectangle &r)
{
bool testResult = false;
if (r.width > 0 && r.length > 0)
testResult = true;
return testResult;
}
rect.h
// Rec header file
#ifndef RECT_H
#define RECT_H
#include "testRect.h"
class Rectangle
{
private:
double width;
double length;
char *name;
static double yardsAvail; //indicate how many yards of perimeter are available to make rectangle
void initName(const char *n);
void initName(const char *n, int size);
public:
//constructors
Rectangle();
Rectangle(double, double,
const char *);
//destructor
~Rectangle() { delete[] name; };
void setWidth(double);
void setLength(double);
void setWidth(char *);
void setLength(char *);
void setName(const char *);
int getWidth() const;
int getLength() const;
double getArea() const;
char *printName() const
{
return name;
}
//added parts
static void setYards(double);
friend class TestRect;
friend bool TestRect::tester(Rectangle &);
};
double Rectangle::yardsAvail = 0; //added parts
#endif
rect.cpp
#include <iostream> //
#include <iomanip>
#include <string>
#include "rect.h"
#include "testRect.h"
using namespace std;
Rectangle::Rectangle()
{
width = 0;
length = 0;
initName("Default");
}
Rectangle::Rectangle(double x, double y, const char *z)
{
width = x;
length = y;
initName(z);
double yardsReqd = 2 * x + 2 * y;
if (yardsAvail - yardsReqd < 0)
{
cout << "Not enough yard..\n";
width = 0;
length = 0;
}
yardsAvail -= yardsReqd;
}
void Rectangle::initName(const char *n)
{
name = new char[258];
strcpy(name, n);
};
void Rectangle::initName(const char *n, int size)
{
name = new char[size];
strcpy(name, n);
};
void Rectangle::setWidth(double w)
{
width = w;
}
void Rectangle::setLength(double l)
{
length = l;
}
void Rectangle::setName(const char *newname)
{
//newname.newName = "Office";
strcpy(name, newname);
}
double Rectangle::getArea() const
{
return width * length;
}
//added part
void Rectangle::setYards(double y)
{
yardsAvail = y;
}

Calculate car movement and distance with C++ classes

This program compiles however, I need to get this function to move on the x & y coordinate and then output the total distance traveled. The xCord moves it right and left while the yCord moves it up and down. I think I need to update my int Taxicab::getDistanceTraveled(), void Taxicab::moveX(int getX), & void Taxicab::moveX(int getX). But for the life of me can't figure out what to do to get it to update properly. When I compile and run it gives me 132617596 for cab1 distance travelled and 0 for the Y coordinate on cab2. Thanks for the help!
#ifndef TAXI_CPP
#define TAXI_CPP
class Taxicab
{
private:
int xCord;
int yCord;
int totalDist;
public:
Taxicab(); //default constructor
Taxicab(int, int); //overload constructor
int getX(); //returns X coordinate
int getY(); //returns Y coordinate
int getDistanceTraveled(); //returns distance calculation
void moveX(int); //moves X left or right
void moveY(int); //moves Y left or right
};
#endif // !TAXI_CPP
#include "Taxi.h"
#include <iostream>
#include <math.h>
#include <cstdlib>
using std::cout;
using std::cin;
using std::endl;
using std::abs;
Taxicab::Taxicab() //default constructor
{
}
Taxicab::Taxicab(int xCord, int yCord) //overload constructor
{
xCord = 0; //initialize to 0
yCord = 0; //initialize to 0
totalDist = 0; //initialize to 0
}
int Taxicab::getX()
{
return xCord; //return x coordinate
}
int Taxicab::getY()
{
return yCord; //return y coordinate
}
void Taxicab::moveX(int getX)
{
int moveX = 0;
moveX = moveX + getX;
}
void Taxicab::moveY(int getY)
{
int moveY = 0;
moveY = moveY + getY;
}
int Taxicab::getDistanceTraveled()
{
return abs(xCord) + abs(yCord);
}
#include <iostream>
#include "Taxi.h"
#include <math.h>
using std::cout;
using std::cin;
using std::endl;
int main()
{
Taxicab cab1;
Taxicab cab2(5, -8);
cab1.moveX(3);
cab1.moveY(-4);
cab1.moveX(-1);
cout << cab1.getDistanceTraveled() << endl;
cab2.moveY(7);
cout << cab2.getY() << endl;
}
Your constructors do not make sense.
In default constructor you have to initialize member variables to something, otherwise their values are undefined and could be set to some random value. Try these maybe:
Taxicab::Taxicab() //default constructor
{
xCord = 0; //initialize to 0
yCord = 0; //initialize to 0
totalDist = 0; //initialize to 0
}
Taxicab::Taxicab(int xCord, int yCord) //overload constructor
{
this->xCord = xCord;
this->yCord = yCord;
totalDist = 0; //initialize to 0
}
Methods to move taxi also do not make much sense. Maybe something like that would be better:
void Taxicab::moveX(int offsetX)
{
totalDist += abs(offsetX);
xCoord += offsetX;
}
void Taxicab::moveY(int offsetY)
{
totalDist += abs(offsetY);
yCoord += offsetY;
}
int Taxicab::getDistanceTraveled()
{
return totalDist;
}

why when accessing data from the base class from a derived class does it return nonsense (pointer data i think)

I am making a collision detection system for a text based game using co-ordinates. I am trying to retrieve the x and y positions of my player and an array of monsters. The co-ordinates are held in a bass class Character. when i try to retrieve the data it returns Xpos -858993460 which i am assuming is comming from the pointers i am using.
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
const int MON_SIZE = 10;
monster* monArr[MON_SIZE];
player player1;
bool collision();
int main(){
void initialise();
player1.moveChar(3, 6);
bool temp;
temp = collision();
if (temp = true){
cout << endl << "collision detected" << endl;
}
system("pause");
return 0;
}
void initialise()
{
srand(time(NULL));
for (int i = 0; i < 10; i++)
{
int inx = rand() % 9;
int iny = rand() % 9;
monArr[i] = new monster();
monArr[i]->moveChar(inx, iny);
}
}
bool collision()
{
bool collision;
for (int i = 0; i < 10; i++)
{
int mx, my, px, py;
monArr[i]->getPos(mx, my);
player1.getPos(px, py);
if (mx == px && my == py)
{
collision = true;
cout << endl << mx << " " << my << endl;
}else collision = false;
}
return collision;
}
#pragma once
#include "character.h"
class player :
public character
{
private:
public:
player();
~player();
};
#pragma once
#include "character.h"
class monster :
public character
{
public:
monster();
~monster();
private:
};
#include "character.h"
#include <iostream>
using namespace std;
character::character()
{
xpos = 0;
ypos = 0;
}
character::~character()
{
}
void character::moveChar(int Xpos, int Ypos)
{
xpos = Xpos;
ypos = Ypos;
}
void character::printPos(){
cout << "Position: " << xpos << " . " << ypos << endl;
}
void character::getPos(int& Xpos, int& Ypos){
Xpos= xpos;
Ypos= ypos;
}
#pragma once
class character
{
public:
character();
~character();
void moveChar(int Xpos, int Ypos);
void printPos();
void getPos(int& Xpos, int& Ypos);
protected:
int xpos;
int ypos;
};
int main(){
void initialise();
...
The above does not call the function initialize. Although you did not post that function, I suppose it initializes your arrays and variables... Write instead:
int main(){
initialise();
...
And move the definition of initialize() to before main, or at least put a declaration of its prototype.
Change your charactoer::getPos function to this:
void character::getPos(int& Xpos, int& Ypos){
Xpos = xpos;
Ypos = ypos;
}
The statement Xpos *= xpos is equivalent to Xpos = Xpos * xpos. This is not what you want, especially since your Xpos argument is not initialize.

C++ updating/changing variables from different class/variables

I'm a noobie at C++ and I was making a game for practice on Visual Studios and I just couldn't figure out how to update stats when exp was added. I tried changing the player level by adding exp but when I add 55 exp the player remained at level 1 still.
Main:
#include <iostream>
#include <windows.h>
#include "Game.h"
using namespace std;
void FalseLoad();
int main() {
//Cool load intro
FalseLoad();
cout << "\n \n";
Game::Game();
system("PAUSE");
return 0;
}
void FalseLoad() {
int i = 0;
int start;
cout << "***Freelancer*** \n \n";
system("PAUSE");
while (i <= 100){
cout << "Loading game... " << i << "% \n";
i++;
Sleep(110 - i);
if (i == 100) {
start = 0;
}
}
}
Game.cpp:
#include <iostream>
#include "Game.h"
using namespace std;
Game::Game() {
Player Player;
Player.Init();
cout << Player.exp << " " << Player.level;
Player.exp += 55;
cout << " " << Player.exp << " " << Player.level << " ";
}
Game.h:
#pragma once
#include "Player.h"
class Game {
public:
Game();
};
Player.cpp:
#include "Player.h"
Player::Player() {
}
void Player::Init() {
int exp = 5;
int level = (exp / 5);
int attack = (10 + (level * 2));
int defense = (10 + (level * 2));
int speed = (10 + (level * 2));
}
Player.h:
#pragma once
class Player
{
public:
Player();
void Init();
int exp = 5;
int level = (exp / 5);
int attack = (10 + (level * 2));
int defense = (10 + (level * 2));
int speed = (10 + (level * 2));
};
If you add 55 to exp, only exp will be changed.
You can write getters and setters and declare the member variables private:
Player.h
#pragma once
class Player
{
public:
Player();
void Init();
void addExp(const int additionalExp);
int getExp();
//... TODO add similar get/set methods for the other members...
private:
int exp = 5;
int level = (exp / 5);
int attack = (10 + (level * 2));
int defense = (10 + (level * 2));
int speed = (10 + (level * 2));
};
and add the method definitions:
#include "Player.h"
Player::Player() {
}
void Player::Init() {
int exp = 5;
int level = (exp / 5);
int attack = (10 + (level * 2));
int defense = (10 + (level * 2));
int speed = (10 + (level * 2));
}
void Player::addExp(const int additionalExp) {
if ( additionalExp < 0 ) return; // think about error handling or use
// unsigned for exp
exp += additionalExp;
level = exp / 50; // or something else, as you like.
}
int Player::getExp(){ return exp; }
// ... TODO add definitions for the other get/set methods...
And use the addExp() method in your main.cpp.
One benefit of having the member variables private is that you get more control in how they get manipulated. E.g. if you add exp, you can set level accordingly simultaneously.

For-Loop Segmentation -- Excessive run ( i < SIZE, but i = SIZE)

This is a function in a program replicating Sierpinski's gasket. This function is supposed to attach the points in the triangle for the fractal.
After much deliberation I've figured out where the issue lies:
void add_pts(int &x, int &y)
{
Vector_ref<Rectangle> pt;
for (int i = 0; i < POINTS; ++i)
{
pt_test; //generates changing x, y vals within the limits of the triangle
cout << "pass" << i <<endl;
pt.push_back(new Rectangle(Point(x,y),5,5));
pt[i].set_fill_color(Color::yellow);
win.attach(pt[i]);
}
}
The output is "pass1...pass[POINTS-1]", but for whatever reason it runs when i = POINTS and runs into the segmentation error. I have no clue as to why. Can anyone assist, please?
Here is my code. The pt_test and coord are a bit sloppy but seeing as it can't run properly it's very hard to ascertain what I can streamline.
#include <stdlib.h>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <time.h>
#include "Simple_window.h"
#include "Graph.h"
#include "Point.h"
#include "GUI.h"
#include "Window.h"
using namespace std;
using namespace Graph_lib;
// globals
const int POINTS = 5000;
unsigned int seed = (unsigned int)time(0);
Simple_window win(Point(100,100),1100,700,"Homework 9");
// function declarations
double random(unsigned int &seed);
bool coords(int &x, int &y);
void pt_test(int x, int y);
void add_pts(int &x, int &y);
int main()
{
int x, y;
// title
Text title(Point(400,50), "The Sierpinski Gasket");
title.set_font(Graph_lib::Font::helvetica_bold);
title.set_font_size(25);
title.set_color(Color::cyan);
win.attach(title);
// triangle
Closed_polyline tri;
tri.add(Point(250,75)); // A
tri.add(Point(850,75)); // B
tri.add(Point(550,675)); // C
tri.set_fill_color(Color::white);
tri.set_color(Color::dark_red);
tri.set_style(Line_style(Line_style::solid,3));
win.attach(tri);
// vertices
Text vert_a(Point(225,70), "A (250, 75)");
vert_a.set_font(Graph_lib::Font::helvetica_bold);
vert_a.set_font_size(15);
vert_a.set_color(Color::cyan);
Text vert_b(Point(855,70), "B (850, 75)");
vert_b.set_font(Graph_lib::Font::helvetica_bold);
vert_b.set_font_size(15);
vert_b.set_color(Color::cyan);
Text vert_c(Point(575,670), "C (550, 675)");
vert_c.set_font(Graph_lib::Font::helvetica_bold);
vert_c.set_font_size(15);
vert_c.set_color(Color::cyan);
win.attach(vert_a);
win.attach(vert_b);
win.attach(vert_c);
// point selection
add_pts(x, y);
// window title and display
win.wait_for_button();
}
double random(unsigned int &seed)
{
const int MODULUS = 15749;
const int MULTIPLIER = 69069;
const int INCREMENT = 1;
seed = ((MULTIPLIER*seed)+INCREMENT)%MODULUS;
return double(seed)/double(MODULUS);
}
bool coords(int &x, int &y) // generates the points
{
x = int(251 + 600*random(seed));
y = int(76 + 600*random(seed));
if( y > (2*x-425) && x<= 550 || x>=550 && y < (-2*x + 1775))
return true;
}
void pt_test(int x, int y) // tests the points until they are within the range
{
coords;
while(coords == 0)
coords;
}
void add_pts(int &x, int &y) // attaches the points as shapes
{
Vector_ref<Rectangle> pt;
for (int i = 0; i < POINTS; ++i)
{
pt_test;
cout << "i == " << i << " points == " << POINTS << endl;
pt.push_back(new Rectangle(Point(x,y),5,5));
pt[i].set_fill_color(Color::yellow);
win.attach(pt[i]);
}
}
I've also noticed that the function add_pts doesn't work when the body is in the loop, but if you put the body in int_main(), it runs indefinitely but doesn't reach the segmentation fault as quickly, if at all.