Ejemplo n.º 1
0
void test1(){
	short a[3]={12,23,34};
	short b[3];
	short *c;
	short *d;
	printf("sizeof(a) is %d\n",sizeof(a));
	printf("sizeof(&a) is %d\n",sizeof(&a));
	printf("sizeof(a[0]) is %d\n",sizeof(a[0]));
	printf("sizeof(&a[0]) is %d\n",sizeof(&a[0]));
	printf("sizeof(a[1]) is %d\n",sizeof(a[1]));
	printf("sizeof(c) is %d\n",sizeof(c));
	printf("sizeof(*c) is %d\n",sizeof(*c));
	printf("a[0] is %d\n",a[0]);
	printf("&a:%x,a:%x,&a[0]:%x,(a+1)%x\n",&a,a,&a[0],(a+1));
	/**
	 *一切都说明,数组名既可以是数组首元素的指针,但又有很多特殊的地方。
	 * 比如:sizeof
	 * 再比如 &a
	 * */
	printf("*(a+1):%d,*(&a+1):%d,*((short *)&a+1):\d\n",*(a+1),*(&a+1),*((short *)&a+1));
	ap(a);
	ap(&a);
	ap(&a[0]);

	ap1(a);
	ap1(&a);
	ap1(&a[0]);
	c=a+1;
	d=&a[0]+1;

	printf("*c:%d,*(c+1):%d,*(c-1):%d,c[1]:%d,c[-1]:%d,1[c]:%d,-1[c]:%d,2[a]:%d\n ",*c,*(c+1),*(c-1),c[1],c[-1],1[c],(-1)[c],2[a]);
}
Ejemplo n.º 2
0
//void test(){
//	SharedPtr sp(new int(2));
//}
void test(){
	AutoPtr<int> ap1(new int(1));
	//DoSomthing();
	{
		AutoPtr<int> ap2(ap1);
	}
	*ap1._ptr = 2;
}
void
test()
{
    B* p1 = new B(1);
    std::auto_ptr<B> ap1(p1);
    std::auto_ptr_ref<A> apr = ap1;
    delete p1;
}
Ejemplo n.º 4
0
void test1(){

	AutoPtr<int> ap(new int(1));
	AutoPtr<int> ap1(ap);

	//ap1 = ap;
	*ap1 = 10;
	//AutoPtr<int> ap2(ap1);
	AutoPtr<A> ap3(new A);
	ap3->a = 30;
}
void
test()
{
    B* p1 = new B(1);
    std::auto_ptr<B> ap1(p1);
    std::auto_ptr_ref<A> apr = ap1;
    std::auto_ptr<A> ap2(apr);
    assert(ap1.get() == nullptr);
    assert(ap2.get() == p1);
    ap2.release();
    delete p1;
}
Ejemplo n.º 6
0
int main()
{
	std::auto_ptr<foo> ap1(new foo);
	ap1->print();
	std::cout << "ap1 pointer: " << ap1.get() << std::endl;

	std::auto_ptr<foo> ap2(ap1);
	ap2->print();
	std::cout << "ap1 pointer: " << ap1.get() << std::endl;
	std::cout << "ap2 pointer: " << ap2.get() << std::endl;

	return 0;
}
Ejemplo n.º 7
0
void
test()
{
    {
    A* p = new A(1);
    std::auto_ptr<A> ap1(p);
    std::auto_ptr<A> ap2(ap1);
    assert(ap1.get() == 0);
    assert(ap2.get() == p);
    assert(A::count == 1);
    }
    assert(A::count == 0);
}
void
test()
{
    {
    B* p1 = new B(1);
    std::auto_ptr<B> ap1(p1);
    std::auto_ptr_ref<A> apr = ap1;
    std::auto_ptr<A> ap2(apr);
    assert(ap2.get() == p1);
    assert(ap1.get() == 0);
    }
    assert(A::count == 0);
    assert(B::count == 0);
}
Ejemplo n.º 9
0
void leeNombres (ifstream &arch, Cadena *personas, int &cant)
{
    Cadena ap1(50);
    Cadena ap2(50);
    Cadena nomb(50);
    cant = 0;
    char buff[200];
    while (arch.getline(buff,200)){
        obtieneNombres(buff, ap1, ap2, nomb);
        ap1.append("/");
        ap2.append("/");
        personas[cant] = ap1 + ap2 + nomb;;
        cant++;
    }
}
void
test()
{
    {
    A* p1 = new A(1);
    std::auto_ptr<A> ap1(p1);
    std::auto_ptr_ref<A> apr = ap1;
    std::auto_ptr<A> ap2(new A(2));
    ap2 = apr;
    assert(A::count == 1);
    assert(ap2.get() == p1);
    assert(ap1.get() == 0);
    }
    assert(A::count == 0);
}
Ejemplo n.º 11
0
Archivo: lct.c Proyecto: jbailhache/log
term ap (term fnc, term arg)
{
type tf, ta;
	tf = type_term (fnc);
	if (tf->k != TYPE_FNC)
		sput ("ap: invalid function\n", err);
	ta = type_term (arg);
	if (!equal_type (ta, tf->fnc.arg))
	{
		sput ("ap: bad type\n\tfunction ", err);
		write_term (fnc, err);
		sput (" has type ", err);
		write_type (tf, err);
		sput ("\n\targument ", err);
		write_term (arg, err);
		sput (" has type ", err);
		write_type (ta, err);
		sput ("\n", err);
	}
	return ap1 (fnc, arg);
}
Ejemplo n.º 12
0
void Squid::draw() {
	
	glPushMatrix();
	glTranslatef(loc.x, loc.y, loc.z);
	glRotatef(rot, 0, 0, 1);
	
	output.setColor(125, 125, 125);
	ofNoFill();
	ofSetLineWidth(3);
	
	output.beginShape();
	
	float cenX		= 0;
	float cenY		= 0;
	
	float pct = _breath / (MAX_INHALE_BREATH - MIN_INHALE_BREATH);
	float rad2 = (MAX_INHALE_BREATH - MIN_INHALE_BREATH) * pct;
	
	float bw = (BODY_WIDTH * .5);
	float bh = (BODY_HEIGHT * .25) + ( (BODY_HEIGHT * .25) * (1 - _pctBreath));
	
	float topBw = bw * .7;
	float botBw = bw * 1.5;
	
	float botCtPtSpread = botBw * .25;
	float bodyCtPtSpread = bh * .25;
	
	ofxVec3f ap1(cenX + topBw, cenY - bh, 0);
	
	ofxVec3f cp1a(cenX + rad2, cenY - bodyCtPtSpread, 0 );
	ofxVec3f cp1b(cenX + rad2, cenY + bodyCtPtSpread, 0 );
	
	ofxVec3f ap2(cenX + botBw, cenY + bh, 0);
	
	ofxVec3f cp2a(cenX + botCtPtSpread, (cenY + bh) + (bh * .25), 0);
	ofxVec3f cp2b(cenX - botCtPtSpread, (cenY + bh) + (bh * .25), 0);
	
	ofxVec3f ap3(cenX - botBw, cenY + bh, 0);
	
	ofxVec3f cp3a(cenX - rad2, cenY + bodyCtPtSpread, 0);
	ofxVec3f cp3b(cenX - rad2, cenY - bodyCtPtSpread, 0);
	
	ofxVec3f ap4(cenX - topBw, cenY - bh, 0);
	
	ofxVec3f cp4(cenX, (cenY - bh) - (bh * .1), 0);
	
	output.polyVertex(ap1.x, ap1.y);
	
	output.bezierVertex(cp1a.x, cp1a.y, cp1b.x, cp1b.y, ap2.x, ap2.y);
	
	output.bezierVertex(cp2a.x, cp2a.y, cp2b.x, cp2b.y, ap3.x, ap3.y);
	
	output.bezierVertex(cp3a.x, cp3a.y, cp3b.x, cp3b.y, ap4.x, ap4.y);
	
	output.bezierVertex(cp4.x, cp4.y, cp4.x, cp4.y, ap1.x, ap1.y);
	
	output.endShape(true);
	
	
	ofFill();
	ofSetColor(200, 200, 200);
	ofCircle(cp1a.x, cp1a.y, 2);
	ofCircle(cp1b.x, cp1b.y, 2);
	ofCircle(cp2a.x, cp2a.y, 2);
	ofCircle(cp2b.x, cp2b.y, 2);
	ofCircle(cp3a.x, cp3a.y, 2);
	ofCircle(cp3b.x, cp3b.y, 2);
	ofSetColor(0, 0, 0);
	//ofCircle(cp4.x, cp4.y, 2);
	
	ofSetColor(150, 150, 150);
	ofCircle(ap1.x, ap1.y, 1);
	ofCircle(ap2.x, ap2.y, 1);
	ofCircle(ap3.x, ap3.y, 1);
	ofCircle(ap4.x, ap4.y, 1);
	
	glPopMatrix();
	
	_renderTentacles();
}