나는 우리가 어떤 하나의 도움말 줘요 C를 사용하지 않을 수도 내 프로젝트에서이 파일을 사용할 수 있습니다 어떻게 MathUtils.h다른 파일에서 .mm 파일의 C++ 클래스 개체를 사용하는 방법은 무엇입니까?
#include "iostream"
및 MathUtils.cpp
#include "MathUtils.h"
using namespace std;
//Box class .....................
class Box
{
private:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
public:
void setParameters(int l,int b,int h);
int volume();
int area();
};
void Box::setParameters(int l, int b, int h)
{
length=l;
breadth=b;
height=h;
}
int Box::volume()
{
return length*breadth*height;
}
int Box::area()
{
return (2*(length*breadth) + 2*(breadth*height) + 2*(height*length));
}
//sphere class................
class Sphere
{
private:
double pi=3.14;
double r;
public:
void setParameters(int radius);
int volume();
int area();
};
void Sphere::setParameters(int radius)
{
r=radius;
}
int Sphere::volume()
{
return (4/3)*pi*r*r;
}
int Sphere::area()
{
return 4*pi*r*r;
}
두 개의 파일을 만든 ++ 내 프로젝트의 파일 그래서 다른 viewController 파일에서 Box 및 Sphere 클래스 개체를 어떻게 사용할 수 있는지 알고 싶습니다. 감사합니다. .
당신이 그것을 봤나요 : 상자에 대한 귀하의 멤버 함수는 여전히 다음을 사용할 수있다
mathutils.c
뷰 컨트롤러에서 함수에 있어야? – Geoffroy
XCode를 사용하는 경우 http://www.brandonpate.org/?p=34 – user1929959