本文整理汇总了C++中Foo::test13方法的典型用法代码示例。如果您正苦于以下问题:C++ Foo::test13方法的具体用法?C++ Foo::test13怎么用?C++ Foo::test13使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Foo
的用法示例。
在下文中一共展示了Foo::test13方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
cout << "main: This routine tests const conditions." << endl;
Foo F;
RCP<Bar> Bptr = rcp(new Bar);
Bptr->setx(10.0);
F.setBar(Bptr);
cout << "Correct output is x = 10." << endl;
cout << "x = " << Bptr->getx() << endl;
F.test1(Bptr);
cout << "Correct output is x = 15." << endl;
cout << "x = " << Bptr->getx() << endl;
// This demonstrates that Bptr was overwritten in this member fcn call with a
// different RCP object, which is only possible because the argument
// list definition was nonconst.
F.test3(Bptr);
cout << "Correct output is x = 25." << endl;
cout << "x = " << Bptr->getx() << endl;
Bptr = F.test5();
cout << "Correct output is x = 15." << endl;
cout << "x = " << Bptr->getx() << endl;
Bptr->setx(35.0);
// Bptr = F.test6(); // not allowed because Bptr is nonconst and output of test6 is const
RCP<const Bar> BptrConst = rcp(new Bar(40.0));
F.setConstBar(BptrConst);
cout << "Correct output is x = 40." << endl;
cout << "x = " << F.test6()->getx() << endl; // valid because we put const after Bar::getx
Bptr = F.test7();
cout << "Correct output is x = 35." << endl;
cout << "x = " << Bptr->getx() << endl;
Bptr = F.test8();
cout << "Correct output is x = 45." << endl;
cout << "x = " << Bptr->getx() << endl;
//F.test8() = rcp(new Bar(50.0)); // not allowed because output is const.
F.test9() = rcp(new Bar(60.0)); // allowed because output is nonconst, but
// this is crazy. Especially since the object that is modified is a copied
// object, so we don't have access to it after this call.
F.test10() = rcp(new Bar(65.0)); // allowed because output is nonconst, and
//this does something strange, as it modifies the internal data to the class
// through a nonconst reference passed out.
Bptr = F.test7(); // grab it back out with const output
cout << "Correct output is x = 65." << endl;
cout << "x = " << Bptr->getx() << endl;
// F.test7() = rcp(new Bar(70.0)); // not allowed because output is const, this
// is the expected behavior. You shouldn't be able to do assignments like this.
BptrConst = F.test12();
cout << "Correct output is x = 40." << endl;
cout << "x = " << BptrConst->getx() << endl;
//Bptr = F.test12(); // not allowed because Bptr is nonconst
BptrConst = F.test13(); // this is okay.
cout << "Correct output is x = 40." << endl;
cout << "x = " << BptrConst->getx() << endl;
Bptr = F.test14(); // this is okay.
cout << "Correct output is x = 65." << endl;
cout << "x = " << Bptr->getx() << endl;
Bptr = F.test15(); // this is okay.
cout << "Correct output is x = 65." << endl;
cout << "x = " << Bptr->getx() << endl;
return(0);
}