int tdfeTestCase33Execute(void) { Derived *pDerived; pDerived=new Derived; pDerived->vF1(); return 0; }
int main( int argc, char **argv) { Derived d; d.testDerived1(); return 0; }
void testDefaultParams(const char* mode) { // One object of type Base and one of type derived Base *base = new Base(mode); Derived *derived = new Derived(mode); // Another of type Base pointing to a Derived Base *base_der = derived; // Default parameter of the base funtion base->FunctionX(); // Default parameter of the derived funtion derived->FunctionX(); // Default parameter of the base funtion again!!! // Note: they are evaluated according to their static // type since in this case it's "Base *base_der" base_der->FunctionX(); base->FunctionY(); // counter: 1 derived->FunctionY(); // counter: 2 base_der->FunctionY(); // counter: 3 base_der->FunctionY(42, 42); // counter: unchanged! base->FunctionY(); // counter: 4 derived->FunctionY(); // counter: 5 base_der->FunctionY(); // counter: 6 delete base; delete derived; }
// ---------------------------------------------------------------------------- int main(int argc, char** argv) { DBG("[Lesson 5]: Vtable 11"); Base base; Derived derived; Further further; Base* pb = &base; Base* pd = &derived; Derived* pf = &further; DBG("Pointer to Base"); pb->foo(); pb->bar(); pb->ext(); DBG("Pointer to Derived"); pd->foo(); pd->bar(); pd->ext(); DBG("Pointer to Further"); pf->foo(); pf->bar(); pf->ext(); DBG("[Lesson 5]: Vtable 11 [END]"); return 0; }
int main() { // pointer to virtual table // {<BaseA> = {_vptr.BaseA = 0x4010b0, a = 1}, <BaseB> = {_vptr.BaseB = 0x4010d0, b = 2}, c = 3} Derived d(1, 2, 3); Derived* pd = &d; cout << "pd address: " << pd << endl; void* pv = pd; cout << "pv address: " << pv << endl; BaseA* pa = pd; cout << "pa address: " << pa << endl; pa->fa(); BaseB* pb = pd; //@ pb point to BaseB section. cout << "pb address: " << pb << endl; pb->fb(); // Derived* pdd = pa; // error: invalid conversion from ‘BaseA*’ to ‘Derived*’ Derived* pdd = dynamic_cast<Derived*>(pa); cout << "pdd address: "<< pdd << endl; pdd->fd(); return 0; }
int main(int argc, char* argv []) { Derived d; d.Teste(); return 0; }
void call_derived(Base* b) { Derived* d = dynamic_cast<Derived*>(b); if (d != nullptr) { d->derivedfunc(); } else { printf("cast failed\n"); } }
int main() { Derived *d = new Derived(); d->mf1(); //d->mf1(1); //d->mf3(); //d->mf3(1.20); }
int main() { Derived d {6}; auto inner = d.produce_inner(); inner->f(); inner->g(7); inner->f(); }
int main() { Derived d; string str = d.input(); d.print(str); getchar(); return 1; }
//-------------------------------------------------------------------------------------------------- int main (int argc, char** argv) { Base* pBase = new Base; Derived* pDerived; pDerived = static_cast<Derived*>(pBase); pDerived->Dummy(); return 0; }
int main() { Derived drv; drv.showBs0(); return 0; }
int main() { Derived d; d.foo( 1 ); d.virtual_method( ); return 0; }
int main() { Derived *d = new Derived(); d->Foo(); d->ParentFoo(); delete d; return 0; }
static ret_type_1<T,Term> subs_term_impl(const Term &t, const std::string &name, const T &x, const symbol_set &s_set) { Derived tmp; tmp.set_symbol_set(s_set); tmp.insert(Term(typename Term::cf_type(1),t.m_key)); // NOTE: use moves here in case the multiplication can take advantage. return math::subs(t.m_cf,name,x) * std::move(tmp); }
int main() { Base B; Derived D; D.Data1(); B.Data(); return 0; }
int main() { Derived d; Base b; b.memfcn(); // calls Base::memfcn d.memfcn(10); // calls Derived::memfcn d.memfcn(); // error: memfcn with no argument d.Base::memfcn(); // ok: calls Base::memfcn return 0; }
void passByReference(Base& b, Derived& d) { cout << "In passByReference function" << endl; b.func(52); d.func(52); b.func(); d.func(); }
void test() { Derived* p; *(reinterpret_cast<void**>(&p)) = new C; p->f(); // We should still be able to do some reasoning about bindings. p->x = 42; clang_analyzer_eval(p->x == 42); // expected-warning{{TRUE}} };
int main (int argc, char const *argv[]) { Derived a; cout << a.get_y() << endl; Derived2 b; cout << b.get_y() << endl; return 0; }
DMatrix & DenseIO<Derived>::outputD(int i) { Derived* d = static_cast<Derived*>(this); if (d->output(i).isdense()) { return d->output(i); } else { return dense_outputs_[i]; } }
int main(){ Derived drv; drv.showBs1(); drv.showBs2(); drv.showDr(); return 0; }
int main() { Derived d; d.display(); //调用调用的是本类的同名函数 // 如果要调用基类被隐藏的同名函数,可以使用作用域 // 分辨符来调用,如下: d.Base::display("qianghaohao"); return 0; }
int main() { Derived d; d.Teste(); Base b; b.Teste(); return 0; }
int main(){ Derived *d = new Derived(); assert(d->Base1::f() == 21); assert(d->Base2::f() == 42); assert(d->g() == 42); delete d; return 0; }
int main() { Base B; Derived C; B.print(); C.print(); C.Base::print(); return 0; }
const DMatrix & DenseIO<Derived>::inputD(int i) const { Derived* d = static_cast<Derived*>(this); if (d->input(i).isdense()) { return d->input(i); } else { return dense_inputs_[i]; } }
int main(){ Derived d; Base* d2 = d.clone(); d2->f(); delete d2; invoke_f_and_die(d.clone()); }
int _tmain(int argc, _TCHAR* argv[]) { { Derived derived; derived.DoSomething(); } cout << "Good bye!" << endl; return 0; }
int main() { Derived* d = new Derived(); Base* b = d; b->f(65.3);//Base:f d->f(65.3);//Base:f d->Base::f(65.3);//Base:f // This methode is more desirable because Base class methode still gets hidden which is not case with using :: delete d; return 0; }