Você está na página 1de 4

!

"

# %
int *intPtr;
int intArray[10];
intPtr = new int; intArray[0] = 6837;

*intPtr = 6837; #
*intPtr 6837
intPtr 0x0050
int *intArray;
delete intPtr; $ intArray = new int[10];
intArray[0] = 6837;
int otherVal = 5; intPtr
intPtr = &otherVal; ...

*intPtr 5 otherVal delete[] intArray;


intPtr 0x0054 &otherVal

#
&& '
int add(int a, int b) { ) % 'a b
char myString[20]; return a+b;
strcpy(myString, "Hello World"); }

int a, b, sum;
# NULL '\0' sum = add(a, b);

myString[0] = 'H';
'
myString[1] = 'i';
myString[2] = '\0'; int add(int *a, int *b) { '
return *a + *b; a b* a
printf("%s", myString); (Hi } b '
add
int a, b, sum;
sum = add(&a, &b);
-
' , #ifndef _IMAGE_H_
'
#define _IMAGE_H_
int add(int &a, int &b) {
return a+b; #include <assert.h> . '
} #include "vectors.h“
. '
int a, b, sum; class Image {
sum = add(a, b);
public: ! '
...
'
private:
... ! '
'
};

#endif

/ #
# % image.h ' ( ' '
Image myImage; void SetAllPixels(const Vec3f &color);
myImage.SetAllPixels(ClearColor);

image.C * ' (" ' '


void Image::SetAllPixels(const Vec3f &color) {
for (int i = 0; i < width*height; i++)
Image *imagePtr; data[i] = color;
imagePtr = new Image(); }
imagePtr->SetAllPixels(ClearColor);
main.C ) (" '
...

delete imagePtr; myImage.SetAllPixels(clearColor);

$
class Image { %
public:
Image(void) { Image(int w, int h) {
width = height = 0; width = w;
data = NULL; height = h;
} data = new Vec3f[w*h];
}
~Image(void) {
if (data != NULL)
0 % (
delete[] data;
}
Image myImage = Image(10, 10); %
int width;
int height; Image *imagePtr;
Vec3f *data; imagePtr = new Image(10, 10);
};

+
Image(Image *img) { .' ' 2
width = img->width;
% *
height = img->height;
data = new Vec3f[width*height];
bool IsImageGreen(Image img);
for (int i=0; i<width*height; i++)
data[i] = new data[i];
} 3

' 2
( .4 ' ' (

Image(Image *img) { bool IsImageGreen(Image *img);


width = img->width;
height = img->height;
data = img->data; bool IsImageGreen(Image &img);
}

'
5 1$ Sphere::Sphere() : Object3D() {
class Object3D { radius = 1.0;
Vec3f color; }
};

class Sphere : public Object3D { # '


float radius; class Object3D {
}; virtual void setDefaults(void) {
color = RED; }
class Cone : public Object3D { };
float base;
float height; class Sphere : public Object3D {
}; void setDefaults(void) {
color = BLUE;
radius = 1.0 }
};

! " main '


' 5 3
Sphere *mySphere = new Sphere(); int main(int argc, char** argv);
Object3D *myObject = mySphere;

.' ' 2 6 ' '

class Object3D {
argv[0]
virtual void intersect(Vec3f *ray, Vec3f *hit);
}; argv[1] argv[argc-1] 7
#

class Sphere : public Object3D {


virtual void intersect(Vec3f *ray, Vec3f *hit);
};
#

myObject->intersect(ray, hit); Sphere::intersect

1
9# ' ; <:
0 #define '
(
#define PI 3.14159265
#define sinf sin
int intArray[10]; '
intArray[10] = 6837;
0 printf cout ' '
printf("value: %d, %f\n", myInt, myFloat);
cout << "value:" << myInt << ", " << myFloat << endl; Image *img;
img->SetAllPixels(ClearColor); 60==
0 assert ' 9 :
assert(denominator != 0);
quotient = numerator/denominator;
' ''
2 *

= ' 2 ' > '

friend protected
'
const static '
'
virtual void Intersect(Ray &r, Hit &h) = 0;

Vec3f& operator+(Vec3f &a, Vec3f &b);

Você também pode gostar