Real C++ compile problems
Real C++ compile problems
Thank you all for your initial help with Xcode and seeing the flaws in my code. Sometimes when you write it yourself your blind to your own mistakes.
But THIS time Im having a confusing error. My program compiles and runs fine in unix, whereas in Xcode my errors are:
square.h:32: error: call of overloaded `sqrt(int)' is ambiguous
math.h:302: error: candidates are: double sqrt(double)
cmath:461: error: float std::sqrt(float)
cmath:465: error: long double std::sqrt(long double)
It looks like its having trouble with my sqrt calls. I dont know why its saying the call is overloaded. Also I didnt write the math.h or cmath.h programs, so I hope theres no errors there.
Im also wondering if Im starting up Xcode correctly for C++ programs. When I do File>New Project, I end up selecting "Tools>C++ Tool". Im not sure if this is the best way to start. And ALSO *in Xcode* when Im writing a linked class, I choose File>New File then select "Carbon>C++ Class". I hope this is correct. I put all my code into the additional *.h files that are created in the class, but Im not sure what to do about the *.m files which seem to be linked to the *.h files anyway. So I leave them blank.
Im including my code for my main program called 2_21.c and all the classes that go with it (square.h, rectangle.h, and circle.h)
-----
//2_21.c
#include <iostream>
#include "circle.h"
#include "square.h"
#include<cmath>
using namespace std;
int main ()
{
square innerSq(4);
circle circ(innerSq.diagonal()/2);
square outerSq(circ.getRadius()*2);
cout<<"The area of the crossline section is: "<<circ.area()-innerSq.area()<<endl;
cout<<"The perimeter of the shaded region is: "<<outerSq.perimeter()<<endl;
return 0;
}
---------------------------------------
//square.h
#include"rectangle.h"
#include<cmath>
class square
{
public:
square(double len);
double getSide() const;
void setSide(double len);
double perimeter() const;
double area() const;
double diagonal() const;
private:
rectangle sq;
};
square::square(double len):sq(len, len)
{}
double square::getSide() const
{return sq.getLength();}
void square::setSide(double len)
{sq.setSides(len,len);}
double square::area() const
{return sq.area();}
double square::diagonal() const
{return sqrt(2)*getSide();}
double square::perimeter() const
{return sq.perimeter();}
--------------------------
//rectangle.h
#include"rectangle.h"
#include<cmath>
class square
{
public:
square(double len);
double getSide() const;
void setSide(double len);
double perimeter() const;
double area() const;
double diagonal() const;
private:
rectangle sq;
};
square::square(double len):sq(len, len)
{}
double square::getSide() const
{return sq.getLength();}
void square::setSide(double len)
{sq.setSides(len,len);}
double square::area() const
{return sq.area();}
double square::diagonal() const
{return sqrt(2)*getSide();}
double square::perimeter() const
{return sq.perimeter();}
-------------------
//circle.h
const double pi = 3.141592653589793;
class circle
{
public:
circle(double r = 0.0): radius(r)
{}
double getRadius() const
{return radius;}
void setRadius(double r)
{radius = r;}
double area() const
{return pi*radius*radius;}
double circumference() const
{return 2.0*pi*radius;}
private:
double radius;
};
------------
THANKS SO MUCH!!!
oliver
The most personalized portal on the Web!
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.