Example #1
0
File: 3.cpp Project: shixv/test
int main(void)
{
	Parent *pp = new Child(10, 20);
	pp->print(); //发生多态 会调用Child 的print函数
	delete pp;
	return 0;
}
Example #2
0
PMediaParent*
AllocPMediaParent()
{
  Parent<PMediaParent>* obj = new Parent<PMediaParent>();
  obj->AddRef();
  return obj;
}
Example #3
0
int main()
{
	Container def;
	Container custom("custom string");

	def.setVarString("new string");

	cout<<def.getVarString()<<endl;

	Child child(1000);
	cout<<child.getVar1()<<endl;

	Parent& ob = child;
	cout<<ob.getVar1()<<endl;

	Parent* obj = new Child(0);
	cout<<obj->getVar1()<<endl;
	delete obj;

	vector<Child> list(10,Child(100));
	for(int i = 0; i < 100; ++i)
	{
		cout<<"list["<<i<<"]"<<" = "<<list[i].getVar1()<<endl;
	}

}
Example #4
0
int main(int argc, char const* argv[])
{
    Parent *p = new Derived();
    p->Test();

    return 0;
}
Example #5
0
int main() {
  int a = 10;
  int* p = new int(1000);
  int& ref = a;

  std::cout << "Values of a p and ref: " << a << " " << *p << " " << ref << "\n";

  // Modify ref, check if a changed.
  ++ref;
  std::cout << "a and ref: " << a << " " << ref << "\n";

  // Implicit subclass to parent class pointer conversion
  Parent* parentP = new Child();
  parentP->print();
  Child* childP = static_cast<Child*>(parentP);
  childP->print();
  Parent* parentP1 = new Parent();
  parentP1->print();

  Child child = Child();
  parentP = &child;
  (*parentP).print();
  parentP = parentP1;
  parentP->print();
  child.print();
  
  return 0;
}
Example #6
0
Bool testlist::Parent::pushFreeParent(const Parent & child)  {
    if( !child.isExists())
        return false;
    child.setNextParentFreeParent(getFirstFreeParent());
    setFirstFreeParent(child);
    setNumFreeParents(getNumFreeParents() + 1);
    child.setupFreeParentHandler();
    return true;
}
Example #7
0
testlist::Parent testlist::Parent::popFreeParent()  {
    Parent result = getFirstFreeParent();
    if(result.isValid())
    {
        result.removeFreeParentHandler();
        setFirstFreeParent(result.getNextParentFreeParent());
        result.setNextParentFreeParent(Parent());
        setNumFreeParents(getNumFreeParents() - 1);
    }
    return result;
}
Example #8
0
int main(int argc, char* argv[])
{
  Parent  *p;
  Child   c;

  p = &c;     //父类类型的指针可以指向子类对象
  p->foo();   //输出:foo in Parent,可见仍旧调用父类的方法
  //p->bar(); //编译的时候提示出错了,Parent不存在bar方法

  return 0;
}
Example #9
0
int main (const int, const char* const [])
{
    Base a;
    std::cout << a.foo() << '\n';

    Parent P;
    std::cout << P.foo() << '\n';

    //std::cout << Base::A << '\n';

    return 1;
}
Example #10
0
int main(int argc, char* argv[])
{
    Parent *p;
    Child1 c1;    //Child1对Parent所有的纯虚函数进行了实现,因此可以创建对象
    //Child2 c2;  //编译出错:Child2没有对Parent所有的纯虚函数进行实现,提示C仍旧是一个抽象类,因为包含纯虚函数bar

    p = &c1;
    p->foo();
    p->bar();

    return 0;
}
Example #11
0
        void operator () (const Index&, Parent& parent) {

            UnionNode* union_node = union_node_;
            auto propagate_fn = [union_node](const ValueType& input) {
                                    union_node->PushItem(input, Index::index);
                                };

            // close the function stacks with our pre ops and register it at
            // parent nodes for output
            auto lop_chain = parent.stack().push(propagate_fn).fold();
            parent.node()->AddChild(union_node_, lop_chain, Index::index);
        }
Example #12
0
int main( int _argc, char* _argv[] )
{
  Parent* p = new Child;
  p->fun1();
  p->fun2();
  p->fun3();
  p->fun4();
  ( ( Child* )p )->fun1();
  ( ( Child* )p )->fun2();
  ( ( Child* )p )->fun3();
  ( ( Child* )p )->fun4();
  delete p;
  return 0;
}
Example #13
0
testlist::Parent testlist::Parent::create()  {
    if(instanceCount() == 0)
        return Parent();
    Parent result = popFreeParent();
    if(!result.isValid())
    {
        if(getUsed() >= instanceCount())
            reallocInstances(instanceCount() << 1);
        result = Parent(getUsed());
        setUsed(getUsed() + 1);
    }
    result.reset();
    result.onCreate();
    return result;
}
Example #14
0
Bool testhash::Parent::insertAfter__ChildTableBlock__Parent(const Parent & child, const Parent & prev)  {
    if( !child.isExists() || !prev.isExists())
        return false;
    Parent next = prev.getNextParent__ChildTableBlock__Parent();
    prev.setNextParent__ChildTableBlock__Parent(child);
    child.setPrevParent__ChildTableBlock__Parent(prev);
    child.setNextParent__ChildTableBlock__Parent(next);
    if(next.isValid())
        next.setPrevParent__ChildTableBlock__Parent(child);
    else
        setLast__ChildTableBlock__Parent(child);
    setNum__ChildTableBlock__Parents(getNum__ChildTableBlock__Parents() + 1);
    child.setup__ChildTableBlock__ParentHandler();
    return true;
}
Example #15
0
Bool testhash::Parent::insertBefore__ChildTableBlock__Parent(const Parent & child, const Parent & next)  {
    if(!child.isExists() || !next.isExists())
        return false;
    Parent prev = next.getPrevParent__ChildTableBlock__Parent();
    next.setPrevParent__ChildTableBlock__Parent(child);
    child.setNextParent__ChildTableBlock__Parent(next);
    child.setPrevParent__ChildTableBlock__Parent(prev);
    if(prev.isValid())
        prev.setNextParent__ChildTableBlock__Parent(child);
    else
        setFirst__ChildTableBlock__Parent(child);
    setNum__ChildTableBlock__Parents(getNum__ChildTableBlock__Parents() + 1);
    child.setup__ChildTableBlock__ParentHandler();
    return true;
}
Example #16
0
Bool testhash::Parent::pushFront__ChildTableBlock__Parent(const Parent & child)  {
    if(!child.isExists())
        return false;
    Parent first_child = getFirst__ChildTableBlock__Parent();
    child.setNextParent__ChildTableBlock__Parent(first_child);
    if(first_child.isValid())
        first_child.setPrevParent__ChildTableBlock__Parent(child);
    else
        setLast__ChildTableBlock__Parent(child);
    child.setPrevParent__ChildTableBlock__Parent(Parent());
    setFirst__ChildTableBlock__Parent(child);
    setNum__ChildTableBlock__Parents(getNum__ChildTableBlock__Parents() + 1);
    child.setup__ChildTableBlock__ParentHandler();
    return true;
}
Example #17
0
int main(int argc, char* argv[])
{
  Parent par;

  int chpid;
  if((chpid=fork())==0)
  {
     Child ch;
     ch.run();
  }
  par.run();

  int status;
  wait(&status);

  return 0;
}
Example #18
0
testhash::Parent testhash::Parent::popFront__ChildTableBlock__Parent()  {
    Parent result = getFirst__ChildTableBlock__Parent();
    if(result.isValid())
    {
        result.remove__ChildTableBlock__ParentHandler();
        Parent next = result.getNextParent__ChildTableBlock__Parent();
        result.setNextParent__ChildTableBlock__Parent(Parent());
        result.setPrevParent__ChildTableBlock__Parent(Parent());
        setFirst__ChildTableBlock__Parent(next);
        if(!next.isValid())
            setLast__ChildTableBlock__Parent(Parent());
        else
            next.setPrevParent__ChildTableBlock__Parent(Parent());
        setNum__ChildTableBlock__Parents(getNum__ChildTableBlock__Parents() - 1);
    }
    return result;
}
Example #19
0
File: 4.cpp Project: shixv/test
int main(void)
{
	Child array[] = { Child(0), Child(1), Child(2) };
	//						array[0]    array[1]  array[2]
	Child *cp = &array[0];
	Parent *pp = &array[0];
	cp->print(); // 子类
	pp->print(); // 子类
	//父类指针 指向子类对象的时候, 如果想发生多态,不要给父类指针累加, 
	cp++; //指针的++ cp+= sizeof(Child)
//	pp++;//               cp += sizeof(Parent)
//	cp->print(); // 子类
//	pp->print(); // 子类
	cout << "-----" << endl;
	int i = 0;
	for (i = 0, cp = &array[0], pp = cp; i < 3; i++, cp++, pp = cp) {
		cp->print();
		pp->print();
	}
	return 0;
}
Example #20
0
bool EasyTreeWidgetItem::operator < (const Parent& _other) const
{
    const auto col = treeWidget()->sortColumn();

    switch (col)
    {
        //case COL_UNKNOWN:
        case COL_NAME:
        {
            if (parent() == nullptr)
                return false; // Do not sort topLevelItems by name
            return Parent::operator < (_other);
        }

        case COL_NCALLS_PER_THREAD:
        case COL_NCALLS_PER_PARENT:
        case COL_NCALLS_PER_FRAME:
        {
            return data(col, Qt::UserRole).toUInt() < _other.data(col, Qt::UserRole).toUInt();
        }

        case COL_SELF_DURATION_PERCENT:
        case COL_PERCENT_PER_PARENT:
        case COL_PERCENT_PER_FRAME:
        case COL_PERCENT_SUM_PER_PARENT:
        case COL_PERCENT_SUM_PER_FRAME:
        case COL_PERCENT_SUM_PER_THREAD:
        {
            return data(col, Qt::UserRole).toInt() < _other.data(col, Qt::UserRole).toInt();
        }

        default:
        {
            // durations min, max, average
            return data(col, Qt::UserRole).toULongLong() < _other.data(col, Qt::UserRole).toULongLong();
        }
    }

    return false;
}
Example #21
0
int main(int argc, char* argv[])
{
  //Parent p;   //编译出错,抽象类不能实例化
  Parent *p;

  Child1 c1;
  Child2 c2;
  //Child3 c3;    //Child3没有对Parent所有的纯虚函数进行重写,因此Child3还是抽象类,仍旧不能实例化
  Child4 c4;

  p = &c1;
  p->foo();       //输出foo in Child1
  
  p = &c2;
  p->foo();       //输出foo in Child2
  //p->bar();     //编译出错,父类的指针不能调用子类新加的方法

  p = &c4;
  p->foo();        //输出foo in Child4,Child4对Child3进行了继承并对其所有的纯虚函数进行了实现,所以可以创建对象
  
  return 0;
}
Example #22
0
File: test48.c Project: 8l/zl
int main() {
  Parent p;
  foo_p(&p);
  Child c;
  foo_c(&c);
  foo_p(&c);
  SuperChild s;
  foo_s(&s);
  foo_c(&s);
  foo_p(&s);

  p.x;
  p.y;
  p.f0();

  c.z;
  c.x;
  c.y;
  c.f0();
  c.f1();
  c.f2();
  c.f3();

  s.z2;
  s.z;
  s.x;
  s.y;
  s.f0();
  s.f1();
  s.f2();
  s.f3();
  s.f4();
  s.f5();
  s.f6();

  return 0;
}
Example #23
0
int main()
{
	Parent p;
	Child c;

	printf("Before try...\n");
	try
	{
		CallA(&p);
		CallA(&c);
		p.B(10);
	}
	catch (int x)
	{
		printf("Catched %i\n", x);
	}
	catch (...)
	{
		printf("Cathced anything\n");
	}
	printf("After catch...\n");
	
	return 0;
}
int main()
{
	//

	Parent p1;
	p1.printP();

	child c1;
	c1.printC();
	c1.printP();


	//赋值兼容性原则 
	//1-1 基类指针 (引用) 指向 子类对象
	Parent *p = NULL;
	p = &c1;
	p->printP();

	//1-2 指针做函数参数

	howToPrint(&p1);
	howToPrint(&c1);

	//1-3 引用做函数参数
	howToPrint2(p1);
	howToPrint2(c1);


	//第二层含义

	//可以让子类对象初始化父类对象
	//子类就是一种特殊的父类
	Parent p3 = c1;

	return 0;
}
Example #25
0
Bool testlist::Parent::insertAfterFreeParent(const Parent & child, const Parent & prev)  {
    if(!prev.isExists() || !child.isExists())
        return false;
    Parent nxt = prev.getNextParentFreeParent();
    child.setNextParentFreeParent(nxt);
    prev.setNextParentFreeParent(child);
    setNumFreeParents(getNumFreeParents() - 1);
    child.setupFreeParentHandler();
    return true;
}
Example #26
0
Bool testhash::Parent::remove__ChildTableBlock__Parent(const Parent & child)  {
    if( !child.isExists())
        return false;
    child.remove__ChildTableBlock__ParentHandler();
    Parent next = child.getNextParent__ChildTableBlock__Parent(), prev = child.getPrevParent__ChildTableBlock__Parent();
    if(next.isValid())
        next.setPrevParent__ChildTableBlock__Parent(prev);
    else if (getLast__ChildTableBlock__Parent() == child)
        setLast__ChildTableBlock__Parent(prev);
    else
        return false;
    if(prev.isValid())
        prev.setNextParent__ChildTableBlock__Parent(next);
    else if (getFirst__ChildTableBlock__Parent() == child)
        setFirst__ChildTableBlock__Parent(next);
    else
        return false;
    child.setNextParent__ChildTableBlock__Parent(Parent());
    child.setPrevParent__ChildTableBlock__Parent(Parent());
    setNum__ChildTableBlock__Parents(getNum__ChildTableBlock__Parents() - 1);
    return true;
}
Example #27
0
    matrify_and_run(Parent& parent, const communicator& comm, const config& cfg,
                    T alpha, MatrixA& A, MatrixB& B, T beta, MatrixC& C)
    {
        const len_type MB = cfg.gemm_mr.def<T>();
        const len_type NB = cfg.gemm_nr.def<T>();

        //block_scatter(comm, C, parent.rscat, MB, parent.rbs,
        //                       parent.cscat, NB, parent.cbs);

        C.fill_block_scatter(0, parent.rscat, MB, parent.rbs);
        C.fill_block_scatter(1, parent.cscat, NB, parent.cbs);

        block_scatter_matrix<T> M(C.length(0), C.length(1), C.data(),
                                  parent.rscat, MB, parent.rbs,
                                  parent.cscat, NB, parent.cbs);

        parent.child(comm, cfg, alpha, A, B, beta, M);
    }
Example #28
0
int main() {
	Parent parent;
	parent.MainLoop();
	return 0;
}
Example #29
0
 int main(int argc, char *argv[]){
	 int height = 900;
	 int width = 900; 

	 xvec = UR - UL;
	 yvec = UL - LL;


	 Film negative(width, height);
	 //Sphere  test = Sphere(Vector3f(0.0f, -.5f, -2.0f), 1.0f, Vector3f(1.0f, 0.0f, 0.0f), Vector3f(.3f, 0.5f, 0.2f));
	 Sphere test = Sphere(Vector3f(-30.0f, 0.0f, -50.0f), 25.0f, Vector3f(.8f, 0.4f, 0.0f), Vector3f(.8f, 0.4f, 0.0f));
	 balls.push_back(test);
	 //Sphere  test2 = Sphere(Vector3f(1.0f, 0.0f, -2.5f), 1.0f, Vector3f(1.0f, 0.0f, 1.0f), Vector3f(.3f, 0.5f, 0.2f));
	 Sphere test2 = Sphere(Vector3f(30.0f, 0.0f, -50.0f), 25.0f, Vector3f(.8f, 0.4f, 0.0f), Vector3f(.8f, 0.4f, 0.0f));
	 
	 balls.push_back(test2);

	 //Plight source(Vector3f(2.0f, 2.0f, 2.0f), 255.0f, 255.0f, 255.0f);
	 Plight source(Vector3f(200.0f, 0.0f, -50.0f), 255.0f, 255.0f, 255.0f);
	 plights.push_back(source);

	 Alight ambient(51.0f, 51.0f, 51.0f);
	 alights.push_back(ambient);

	 for (int i = 0; i < width; i++){
		 for (int j = 0; j < height; j++){
			 Ray * temp = &generateRay(i, j, width, height);
			 Color * result = &trace(temp, balls, 1);
			 negative.commit(i, j, min(result->red, 255.0f), min(result->green, 255.0f), min(result->blue, 255.0f));
			// cout << "Color: (" << i << ", " << j << "): is (" << result->red << ", " << result->green << "," << result->blue << ")" << endl;
			 //FIX ME: currently only supporting one sample per pixel
			 //negative.commit(i, j, 255*i/width, 255*j/height, 200) activate this for pretty colors
		 }
	 }

	 negative.writeImage();
	
	 //testing random shit
	 /*
	 Vector3f v(1.0f, 2.0f, 3.0f);
	 Vector3f w(0.0f, 1.0f, 2.0f);
	 int dotty = v.dot(w);
	 Vector3f sub = v - w; 
	 */
	// Sphere test(Vector3f(5.0f, 5.0f, 5.0f), 5.0f);
	// Ray trial(Vector3f(5.0f+3.0f,5.0f+4.1f, 0.0f), Vector3f(0.0f, 0.0f, 1.0f), 1.0f, 300.0f);
	 //int hh = test.hit(trial);
	// cout << "Dot product: " << hh << endl;


	 //polymorphism dynamic late binding check: should output child1 and child2
	 Child child;
	 Child1 child1;
	 Parent * a = &child;
	 Parent * b = &child1;
	 a->doShit();
	 b->doShit();


	 float num = UL[0];
	 cout << "Dot product: " << num << endl;
	 system("PAUSE");

	 return 0; 
 }
void howToPrint2(Parent &base) // 父类引用
{
	base.printP(); //父类的 成员函数 
}