When I tried to compile my code, I got this in the log:
child 2136(0xD8) died before initialization with status code 0x1
*** child state waiting for longjmp
*** child state waiting for longjmp
Resource temporarily unavailable
C:\Users\Collin\Desktop\Programming\Makefile.win [Build Error] [HW8P1Class.o] Error 2
This is the file that seems to be causing the problem (HW8P1Class.cpp):

#include <iostream>
#include <cmath>
using namespace std;
void point::prompt_values();
{
     cout << "Enter the x-value for the point: ";
     cin >> x;
     cout << "Enter the y-value for the point: ";
     cin >> y;
     cout << "Enter the z-value for the point: ";
     cin >> z;
}
void point::disp_point();
{
     cout << "The x-value for the point is " << x << endl;
     cout << "The y-value for the point is " << y << endl;
     cout << "The z-value for the point is " << z << endl;
}
double point::distance(point cord)
{
       return sqrt(pow((x-cord.x),2)+pow((y-cord.y),2)+pow((z-cord.z),2));
}
int point::compare(point cord)
{
     if ( x==cord.x && y==cord.y && z==cord.z ) return 1;
     else return 0;
}

If it helps, this is the header file for the class:

class point
{
      int x;
      int y;
      int z;
      public:
             point(int=0,int=0,int=0);
             void prompt_values();
             void disp_point();
             double distance(point);
             int compare(point);
}

Recommended Answers

All 37 Replies

I don't know if this will address your problem or not:

class point
{
      int x;
      int y;
      int z;
      public:
             point(int=0,int=0,int=0);
             void prompt_values();
             void disp_point();
             double distance(point);
             int compare(point);
} //<--- This is a problem
  //a semi-colon is required

If you forget the semi-colon after the definition of a class, your compiler will get very confused.

Also, I don't see where you #include your header that defines the point class in the implementation file.

Well.. the error is very strange.. never seen that before. But the source of it is very easy to find:
Your first two functions have a ";" before the opening braces! Two weird errors, two misplaced semi-colons.

Also, where is the implementation for your constructor?
And, you should not use "pow()" function, it is much more efficient to just multiply them out for a simple square power.

I don't exactly know the reason for this error, but few things which you can correct in your code

1. I don't see the header file include in the .cpp file
2. In the definition of prompt_values and disp_point in the .cpp files you have a ';' after the ().

apart from this it seems correct. You have also not provided any definition for the ctor of your class.


EDIT: beaten by a couple of guys here !!

When i compiled i got the error:

1>c:\users\andreas\documents\visual studio 2008\projects\nji\nji\nji.cpp(36) : error C2668: 'pow' : ambiguous call to overloaded function
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\math.h(575): could be 'long double pow(long double,int)'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\math.h(527): or 'float pow(float,int)'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\math.h(489): or 'double pow(double,int)'

So i changed the "2" to "2.0" and it seems to work fine, i dont know why :P

double point::distance(point cord)
{
       return sqrt(pow((x-cord.x),2.0)+pow((y-cord.y),2.0)+pow((z-cord.z),2.0));
}

But still..
this is more efficient:

double point::distance(point cord)
{
  return sqrt((double)((x-cord.x)*(x-cord.x)+(y-cord.y)*(y-cord.y)+(z-cord.z)*(z-cord.z)));
}

When i compiled i got the error:So i changed the "2" to "2.0" and it seems to work fine, i dont know why :P

double point::distance(point cord)
{
       return sqrt(pow((x-cord.x),2.0)+pow((y-cord.y),2.0)+pow((z-cord.z),2.0));
}

It's called function overloading.

There are several definitions of the pow() function. Which one gets called depends on the arguments you provide. There is no version of pow() that works directly with 2 integers. As a result, when pow() is called it promotes the integers to floating-point values, then calls the appropriate version.

The problem is, there is more than 1 appropriate version:
1. double pow(double, int) and
2. float pow(float, int)

When you changed the (2) to a (2.0), you promoted the literal from an integer to a double. Once you did that, you made the call easier to resolve because there is only 1 appropriate version:
1. double pow(double, double).

OK, I changed the things that needed to be changed (like added a semicolon at the closing bracket of the class and implemented the constructor, and included the header, etc.) but i still get the exact same log, along with this before everything else:
Circular HW8P1Main <- HW8P1Main.o dependency dropped.
BTW, I'm using Win 7, MinGW with Dev-C++ IDE, if it helps.
EDIT:
Also, the "Child died" part changed to:
child 6440(0xD8) died before initialization with status code 0x1

Well.. "circular referencing" are you doing something weird like including the cpp in the header and than including the header in the cpp without guards. Or something like that with other source files.

So, you should add a guard to your header file.. a guard means putting as first lines in your header:
#ifndef MY_HEADER_FILE_HPP
#define MY_HEADER_FILE_HPP
Or some other unique name. Then finish the header file with one "#endif"

The child ... part I think is a problem with MinGW and Windows 7. At least by a google search of "died before initialization with status code 0x1" I get tones of results that say it is a MinGW problem with Vista and later versions of windows.

PS: USE LINUX!

Get rid of Dev-C++, it is out-of-date and comes with an out-of-date compiler. Get Code::Blocks or VC++ Express instead...

Trying to compile in code::blocks give me this (and i haven't changed the code at all):
C:\Users\Collin\Desktop\Programming\HW8P1Main.cpp||In function `int main()': |
C:\Users\Collin\Desktop\Programming\HW8P1Main.cpp|10|error: expected primary-expression before "point1"|
C:\Users\Collin\Desktop\Programming\HW8P1Main.cpp|10|error: expected `;' before "point1"|
C:\Users\Collin\Desktop\Programming\HW8P1Main.cpp|12|error: expected primary-expression before "point2"|
C:\Users\Collin\Desktop\Programming\HW8P1Main.cpp|12|error: expected `;' before "point2"|
C:\Users\Collin\Desktop\Programming\HW8P1Main.cpp|14|error: `point1' undeclared (first use this function)|
C:\Users\Collin\Desktop\Programming\HW8P1Main.cpp|14|error: (Each undeclared identifier is reported only once for each function it appears in.)|
C:\Users\Collin\Desktop\Programming\HW8P1Main.cpp|16|error: `point2' undeclared (first use this function)|
||=== Build finished: 7 errors, 0 warnings ===|
Its using the MinGW GCC compiler that came with the install.

You didn't post the main function but I can already say that this error translates to the fact that the compiler cannot figure out what the type of point1 and point2 are. I guess you forgot to include the header for your Point class, or it's two typos.

If you post the relevant portion(s) of your main() we may be able to help a little more.

The first actual error is the second line of the output.

C:\Users\Collin\Desktop\Programming\HW8P1Main.cpp|10|error: expected primary-expression before "point1"|

Notice that I bolded the 10... That means the error is on or before line 10. Generally, this type of error is on the line directly before. It appears that either you have a datatype entered incorrectly or you forgot some punctuation.

No, the problem is that it doesn't recognize the class. There aren't many ways you can mistype "point". And I have all of my punctuation.

Post your current code, that will allow us to look it over and see what is going on. If we don't see the current code, there is nothing more we can do.

My code has not changed at all. And sorry for not posting for the past few days, I was gone.

Well your code is definitely not the problem, it is how you put it together.

Do you have "#include "HW8P1Class.hpp"" at the start of the "HW8P1Main.cpp" file?

And do you add the "HW8P1Class.cpp" to be built along with "HW8P1Main.cpp"?

I can guarantee that if you do this right, it will compiler fine... well unless you have other errors after..

Yes to both of those. But I found the (stupid) mistake. I am notorious for really stupid mistakes. But it still won't compile in Dev-C++, only in Code::Blocks.

I am having problems with this next program. It uses the exact same class and everything. I am pretty sure it is just a problem with my math or something along those lines.

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

int triangle_test (point,point,point);
double perimeter (point,point,point);
double area (double,point,point,point);

int main()
{
    double p;
    double a;
    point point1;
    point point2;
    point point3;
    cout << "Point 1:" << endl;
    point1.prompt_values();
    cout << "Point 2:" << endl;
    point2.prompt_values();
    cout << "Point 3:" << endl;
    point3.prompt_values();
    if ( triangle_test ( point1, point2, point3 ) == 1 )
    {
        cout << "The points form a triangle" << endl;
        p = perimeter ( point1, point2, point3 );
        cout << "The perimeter of the triangle is " << p << endl;
        a = area ( p, point1, point2, point3 );
        cout << "The area of the triangle is " << a << endl;
    }
    else cout << "The points you entered are colinear" << endl;
    cin.ignore();
    cin.get();
    return 0;
}

int triangle_test ( point point1, point point2, point point3 )
{
    bool test = false;
    double side1 = point1.distance ( point2 );
    double side2 = point2.distance ( point3 );
    double side3 = point3.distance ( point1 );
    double temp;
    if ( side1 > side2 + side3 || side2 > side3 + side1 || side3 > side1 + side2 ) return 1;
    else return 0;
}
double perimeter ( point point1, point point2, point point3 )
{
    return point1.distance(point2)+point2.distance(point3)+point3.distance(point1);
}
double area ( double p, point point1, point point2, point point3 )
{
    double side1 = point1.distance ( point2 );
    double side2 = point2.distance ( point3 );
    double side3 = point3.distance ( point1 );
    return sqrt ( p * ( p - side1 ) * ( p - side2 ) * ( p - side3 ) );
}

The program is saying that the set of points {(0,0,0),(2,3,0),(6,9,0)} make a triangle, and most obviously they do not.

You just had a taste of the joys of floating point inaccuracy.
The reason is that although side3 and side1+side2 are mathematically equal for the given points, slight inaccuracies that invariably happen during calculations with floating point types can cause that they end up slightly different, such as 10.816653826391968707 for side3 and 10.81665382639196693 for side1+side2. Note that the first number is slightly greater, but it's enough.
When I compile this in Release mode, it actually works (but if I try to print the values of all sides, it doesn't). Pretty arbitrary, but you can avoid that by working with small delta values when comparing floating point values:

static bool delta_gt(double a, double b)
{
  return a>b+0.00000001;
}

[...]
//in triangle_test:
return delta_gt(side1,side2 + side3) || delta_gt(side2,side3 + side1) || delta_gt(side3,side1 + side2);

By the way, neither point's compare function nor triangle_test should return int.
That's what bool is for. And compare should be operator==.

Mmmm tastes delicious. That fixed it. The only reason I'm not doing any operator overloading or anything is that this is just a homework problem. Anyway, there is another problem. It says that anything I enter into it is collinear. I mean, there is no way that (0,0,0), (4,0,0), and (4,3,0) are collinear, right?

Hm yeah, your test doesn't seem right.

I think this should work, it's based on the fact that if the points a,b,c are on the same line, there's a value r for which a+r(b-a)=c is true.

bool triangle_test ( point a, point b, point c)
{
    if (a.distance(b)<0.000001)return false; //a equals b, can't make a triangle of that
    point ab=b-a;
    double r=(c.x-a.x)/ab.x;
    point ct=a+r*ab;
    return ct.distance(c)>0.000001;
}

point needs some upgrading for that though:

point operator-(const point& p) const
             {
               return point(x-p.x,y-p.y,z-p.z);
             }

             point operator+(const point& p) const
             {
               return point(x+p.x,y+p.y,z+p.z);
             }

             friend point operator*(double r,const point& p)
             {
               return point(r*p.x,r*p.y,r*p.z);
             }

             point operator*(double r) const
             {
               return point(r*x,r*y,r*z);
             }

and the x,y,z members are required to be public (which is fine for a point class).

I was doing the triangle_test the way the homework prompt said to. I can't change how it works alltogether, I just need to implement it the right way.

So, how are you supposed to do it?

It's supposed to see if the largest side is greater than the sum of the two other sides. Exactly as I've been trying to do it.

Sorry about the bump, but I really need help, and soon.

Well, if the sum of the length of two (hypothetical) sides is greater (or equal) than the other, it can't be a triangle.

>>Well, if the sum of the length of two (hypothetical) sides is greater (or equal) than the other, it can't be a triangle.
I think you meant to say: "if the sum of the length of two sides is LESS (or equal) than the other, it can't be a triangle.

Ah, you're right, of course. The first part of my sentence doesn't fit with the second.

Well, thanks for stating the obvious, aranarth. The problem is my implementation, I can't figure out what is wrong with it.

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.