本文整理汇总了C++中Foo类的典型用法代码示例。如果您正苦于以下问题:C++ Foo类的具体用法?C++ Foo怎么用?C++ Foo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Foo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Bar
Bar( Foo& foo )
{
foo.registerCallback( this,
std::bind( &Bar::callback,
this,
placeholders::_1,
placeholders::_2 ),
444 );
}
示例2: TEST
TEST(OwnedTest, Release)
{
Foo* foo = new Foo();
foo->set(42);
Owned<Foo> owned(foo);
EXPECT_EQ(42, owned->get());
EXPECT_EQ(42, (*owned).get());
EXPECT_EQ(42, owned.get()->get());
Foo* raw = owned.release();
EXPECT_EQ(nullptr, owned.get());
EXPECT_EQ(42, raw->get());
delete raw;
EXPECT_EQ(nullptr, owned.get());
}
示例3: main
int main(int argc, char *argv[]) {
int n = 0;
if(argc > 1) {
n = atoi(argv[1]);
}
int ret = foo(3);
try {
bar(n);
} catch(const char *msg) {
fprintf(stderr, "%s.\n", msg);
}
Foo foo;
foo.loop(n);
printf("%d.\n", ret);
return 0;
}
示例4: main
int main() {
class Bar {
public:
Foo a;
void test() {
a.setX(10);
}
};
Foo a = test();
TT c = a;
Bar b;
b.test();
typedef Bar toto_t;
return a.getX();
}
示例5: TEST_F
TEST_F(HazptrTest, basic_refcount) {
constructed.store(0);
destroyed.store(0);
Foo* p = nullptr;
int num = 20;
for (int i = 0; i < num; ++i) {
p = new Foo(i, p);
if (i & 1) {
p->acquire_ref_safe();
} else {
p->acquire_ref();
}
}
hazptr_holder hptr;
hptr.reset(p);
for (auto q = p->next_; q; q = q->next_) {
q->retire();
}
int v = num;
for (auto q = p; q; q = q->next_) {
CHECK_GT(v, 0);
--v;
CHECK_EQ(q->val_, v);
}
CHECK(!p->release_ref());
CHECK_EQ(constructed.load(), num);
CHECK_EQ(destroyed.load(), 0);
p->retire();
CHECK_EQ(constructed.load(), num);
CHECK_EQ(destroyed.load(), 0);
hptr.reset();
/* retire enough objects to guarantee reclamation of Foo objects */
for (int i = 0; i < 100; ++i) {
auto a = new Dummy;
a->retire();
}
CHECK_EQ(constructed.load(), num);
CHECK_EQ(destroyed.load(), num);
}
示例6: func
int func()
{
Bar *bar1, bar2;
Foo foo;
int x = x - 0; // should not warn
static int y = y / 1; // should not warn
float *f;
Bar bar_array[5];
*f = *f / 1; // should not warn
bar1->b_ = bar1->b_ * 1; // should not warn
bar2.c_ = bar2.c_ - 0; // should not warn
foo.setA(5);
bar_array[3].c_ = bar_array[3].c_ * 1; // should not warn
bar_array[x+g].b_ = bar_array[x+g].b_ / 1; // should not warn
x += 0;
y -= 0;
foo = foo;
foo.operator=(foo); // should not warn
}
示例7: l_Foo_add
int l_Foo_add(lua_State * L)
{
Foo * foo = l_CheckFoo(L, 1);
int a = (int)luaL_checknumber(L, 2);
int b = (int)luaL_checknumber(L, 3);
std::string s = foo->Add(a, b);
lua_pushstring(L, s.c_str());
// The Lua stack at this point looks like this:
//
// 4| result string |-1
// 3| metatable "luaL_foo" |-2
// 2| userdata |-3
// 1| string parameter |-4
//
// Return 1 to return the result string to Lua callsite.
return 1;
}
示例8: main
int main(int argc, char* argv[]) { {
Foo a(9);
Foo b = a; // same as Foo b(a);
Foo c(5);
std::cout << a.toString() << std::endl;
std::cout << b.toString() << std::endl;
std::cout << c.toString() << std::endl;
c = a;
std::cout << c.toString() << std::endl;
c = c;
std::cout << c.toString() << std::endl;
std::cout << "Swap test ------------------" << std::endl;
b.setX(10);
std::cout << a.toString() << " " << b.toString() << std::endl;
a.swap(b);
std::cout << a.toString() << " " << b.toString() << std::endl;
} // scoped to print end of main AFTER objects get destructed
std::cout << "::main()" << std::endl;
return 0;
}
示例9: main
// Test app
int main( /* int argc, char* argv[] */ )
{
ossimInit::instance()->initialize();
Foo* f = new Foo;
cout << "count(1): " << f->getRefPtr()->referenceCount() << endl;
ossimRefPtr<Obj> refPtr2 = f->getRefPtr();
cout << "count(2): " << f->getRefPtr()->referenceCount() << endl;
delete f;
f = 0;
cout << "count(1): " << refPtr2->referenceCount() << endl;
refPtr2 = 0; // Should destroy here...
return 0;
}
示例10: TEST
TEST(StrongPointer, move) {
bool isDeleted;
Foo* foo = new Foo(&isDeleted);
ASSERT_EQ(0, foo->getStrongCount());
ASSERT_FALSE(isDeleted) << "Already deleted...?";
sp<Foo> sp1(foo);
ASSERT_EQ(1, foo->getStrongCount());
{
sp<Foo> sp2 = std::move(sp1);
ASSERT_EQ(1, foo->getStrongCount()) << "std::move failed, incremented refcnt";
ASSERT_EQ(nullptr, sp1.get()) << "std::move failed, sp1 is still valid";
// The strong count isn't increasing, let's double check the old object
// is properly reset and doesn't early delete
sp1 = std::move(sp2);
}
ASSERT_FALSE(isDeleted) << "deleted too early! still has a reference!";
{
// Now let's double check it deletes on time
sp<Foo> sp2 = std::move(sp1);
}
ASSERT_TRUE(isDeleted) << "foo was leaked!";
}
示例11: main
int main()
{
QSet<QString *> s;
qDeleteAll(s);
qDeleteAll(s.begin(), s.end());
qDeleteAll(s.values()); // warning
QHash<int, QString *> h;
qDeleteAll(h);
qDeleteAll(h.begin(), h.end());
qDeleteAll(h.values()); // warning
QMap<int*, QString *> m;
qDeleteAll(m);
qDeleteAll(m.begin(), m.end());
qDeleteAll(m.values()); // warning
QMultiHash<int, QString *> mh;
qDeleteAll(mh);
qDeleteAll(mh.begin(), mh.end());
qDeleteAll(mh.values()); // warning
QMultiMap<int, QString *> mm;
qDeleteAll(mm);
qDeleteAll(mm.begin(), mm.end());
qDeleteAll(mm.values()); // warning
qDeleteAll(values()); // ok
Foo foo;
qDeleteAll(foo.values()); // ok
qDeleteAll(foo.doSomethingWithValues(h.values())); // ok
qDeleteAll(m.keys()); // warning
qDeleteAll(keys()); // ok
qDeleteAll(h.values(1)); // warning
}
示例12: main
int main(){
Foo foo;
int x;
char c;
foo.get(x);
foo.get(c);
cout << x << endl;
cout << c << endl;
foo.set('x');
foo.get(x);
foo.get(c);
cout << x << endl;
cout << c << endl;
return 0;
}
示例13: main
int main()
{
// Bar
{
Bar b(8);
DisplayMemberVisitor vis;
apply_fusion_visitor(vis, b);
std::cout << "\n" << vis.complete() << "\n";
Bar cloned;
ReadMemberVisitor rv(vis.complete());
apply_read_fusion_visitor(rv, cloned);
}
std::cout << "\n-----------\n";
// Foo
Foo const f{78};
std::string f_serialized;
{
DisplayMemberVisitor vis;
apply_fusion_visitor(vis, f);
f_serialized = vis.complete();
std::cout << "\n" << f_serialized << "\n";
}
std::cout << "\n-----------\n";
Foo cloned{0};
ReadMemberVisitor rv(f_serialized);
apply_read_fusion_visitor(rv, cloned);
std::cout << "\n-----------\n";
std::cout << f.get_bar_value().get_integer_value() << " == " << cloned.get_bar_value().get_integer_value() << "\n";
}
示例14: main
int main( void )
{
Foo<double, double> a;
Foo<double, float > b;
Foo<float , double> c;
Foo<int , int > d;
a.print(); //==> this is T1 T2 structure.
b.print(); //==> this is T1 float structure.
c.print(); //==> this is float T2 structure.
d.print(); //==> this is int int structure.
func( 1.0 , 2.0 ); //==> this is T1 T2 function.
func( 1.0 , 2.0f ); //==> this is T1 float function.
func( 1.0f, 2.0 ); //==> this is float T2 function.
func( 1 , 2 ); //==> this is int int function.
return 0;
}
示例15: f
class Foo
{
public:
void f()
{
std::cout << "Foo::f()" << std::endl;
}
virtual void g()
{
std::cout << "Foo::g()" << std::endl;
}
}
class Bar : public Foo
{
public:
void f()
{
std::cout << "Bar::f()" << std::endl;
}
virtual void g()
{
std::cout << "Bar::g()" << std::endl;
}
}
int main()
{
Foo foo;
Bar bar;
Foo *baz = &bar;
Bar *quux = &bar;
foo.f(); // "Foo::f()"
foo.g(); // "Foo::g()"
bar.f(); // "Bar::f()"
bar.g(); // "Bar::g()"
// So far everything we would expect...
baz->f(); // "Foo::f()"
baz->g(); // "Bar::g()"
quux->f(); // "Bar::f()"
quux->g(); // "Bar::g()"
return 0;
}