当前位置: 首页>>代码示例>>C++>>正文


C++ Foo::count方法代码示例

本文整理汇总了C++中Foo::count方法的典型用法代码示例。如果您正苦于以下问题:C++ Foo::count方法的具体用法?C++ Foo::count怎么用?C++ Foo::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Foo的用法示例。


在下文中一共展示了Foo::count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(void)
{
    // instantiates static members Foo<string>::ctr and Foo<string>::count
    Foo<string> fs;
    // all three objects share the same Foo<int>::ctr and Foo<int>::count
    // members
    Foo<int> fi1, fi2, fi3;

    Foo<int> fi;        // instantiates Foo<int> class and the static data member ctr
    Foo<int>::count();   // instantiates Foo<int>::count
    fi.count();         // uses Foo<int>::count
  //Foo::count();       // error: which template instantiation?

    return 0;
}
开发者ID:Cuculidae,项目名称:Learn,代码行数:15,代码来源:static.cpp

示例2: main


//.........这里部分代码省略.........
    cout << "after call: " << it << endl;
    it = 43;
    flip3(f2, it, 42); // now it will chg, T2 is a ref
    cout << "after call: " << it << endl;
#endif
#if 0 // rvalues
    string s1("hi"), s2;
    s2 = std::move(string("bye!")); // move from rvalue
    cout << s2 << endl;
    s2 = std::move(s1); // s1 is indeterminate state after move
    cout << s2 << endl;
    g(42);
    // these won't compile
    //const int i = 43;
    //const int& j = i;
    //g(j);
#endif
#if 0
    cout << compare(1,0) << endl;
    string a = "hand", b = "bag";
    cout << compare(b,b) << endl;
    cout << compare("dou","bag") << endl;
    const char *p;
    const char *q;
    char ppp[] = "aaa";
    char qqq[] = "bbb";
    p = &ppp[0];
    q = &qqq[0];
    cout << compare(p, q) << endl; // specialization version

    vector<int> v1{1,2,3};
    vector<int> v2{4,5,6};

    cout << compare(v1, v2) << endl;
    cout << compare(v2, v1) << endl;

    cout << compare(1, 0) << endl;
    cout << compare(0, 1) << endl;
    cout << compare(1, 1) << endl;

    int rc = 42;
    rc = foo(&rc);
    cout << rc << endl;

    const char a2[4] = "bag";
    const char b2[4] = "dog";
    cout << compare(a2, b2) << endl;
    cout << compare2(a2, b2) << endl;
    cout << compare3(1,0) << endl;
    cout << compare3("bat","man") << endl;
    int aa = 2;
    long bb = 1;
    cout << FlexibleCompare(aa, bb) << endl;
#endif
#if 0
    vector<int> vi{1,2,3};
    vector<string> vs{"one","two","three"};
    const vector<string> cvs{"four","five","six"};
    auto &ii = fcn(vi.begin(), vi.end());
    auto &ss = fcn(vs.begin(), vs.end());
    // this one uses type traits
    auto &css = fcn2(cvs.begin(), cvs.end());
#endif
    test_blob();
#if 0

    Foo<int> fi;
    auto ct = Foo<int>::count();
    cout << "ct: " << ct << endl;
    ct = fi.count();
    cout << "ct: " << ct << endl;
    // demo customer deleter
    double *p = new double(3.14);
    DebugDelete d;
    d(p);
    int *ip = new int(42);
    DebugDelete()(ip);
#endif
#if 0
    // we can supply DebugDelete as the deleter to unique_ptr's
    unique_ptr<int, DebugDelete> p2(new int(43), DebugDelete());
    unique_ptr<string, DebugDelete> sp2(new string("dude"), DebugDelete());

    shared_ptr<string> ps(new string("the dawg"), DeleteStringPtr);
    shared_ptr<string> ps2(new string("homi"), my_deleter<string>);
    // reset to different deleter at run-time -- only shared_ptr's not unique_ptr's
    // looks like call to reset will call the original deleter first
    ps2.reset(new string("wusup"), my_deleter2<string>);
#endif
#if 0
    // template overloading
    string s("hi");
    cout << debug_rep(s) << endl;
    cout << debug_rep(&s) << endl;
    cout << debug_rep("hi world!") << endl;
    char s2[] = "hello dude";
    cout << debug_rep(s2) << endl;
#endif

}
开发者ID:walrus7521,项目名称:code,代码行数:101,代码来源:templates.cpp


注:本文中的Foo::count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。