小妹问一下:有没有C++的中等难度的实例的教材?

青松2 2013-06-01 09:41:13
就是专门针对C++的编程例子,难度比C++基础教材上要大,规模也大,对例子解释比较详细的教材,有嘛?

...全文
364 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
jack___coder 2014-03-30
  • 打赏
  • 举报
回复
推介你个ACM练习网址:http://zju.acmclub.com/ 你会感兴趣的。
Win-kill 2013-06-19
  • 打赏
  • 举报
回复
Dobzhansky 2013-06-05
  • 打赏
  • 举报
回复
你看看 tinyxml 源码吧
我看你有戏 2013-06-05
  • 打赏
  • 举报
回复
www.codeproject.com 这里面有些老外的代码,看看不错的,基础掌握,可以开始看具体的小项目了
看着捉急 2013-06-04
  • 打赏
  • 举报
回复
基础的话c++primer足以,每次看都有新体会,你需要的某个系统平台的实际开发经验,自己找些项目做做,看开源项目
dahaiI0 2013-06-04
  • 打赏
  • 举报
回复
看起来好厉害的样子。
BuleRiver 2013-06-04
  • 打赏
  • 举报
回复
可以研究一下STL和BOOST的源码。
u010288740 2013-06-04
  • 打赏
  • 举报
回复
度娘和谷歌是你最好的老师!
yshuise 2013-06-04
  • 打赏
  • 举报
回复
楼主看不看得懂这个例子:
#include "stdafx.h"  
#include <iostream>  
#include <boost/mpl/fold.hpp>  
#include <boost/mpl/filter_view.hpp>  
#include <boost/type_traits/is_same.hpp>  
#include <boost/mpl/vector.hpp>  
#include <boost/mpl/placeholders.hpp>  
#include <boost/mpl/assert.hpp>  
#include <boost/static_assert.hpp>  
#include <vector>  
#include <ctime>  
#include <cassert>   
  
  
namespace mpl = boost::mpl;  
using namespace mpl::placeholders;  
  
//通过递归的“分派”   
template<  
    class Transition  
        , class Next  
>  
struct event_dispatcher  
{  //Finite State Machines   
    typedef typename Transition::fsm_t fsm_t;  
    typedef typename Transition::event event;  
  
    static int dispatch(  
        fsm_t& fsm, int state, event const& e)  
    {  
        if (state == Transition::current_state)  
        {  
            Transition::execute(fsm, e);  
            return Transition::next_state;  
        }  
        else // move on to the next node in the chain.   
        {  
            return Next::dispatch(fsm, state, e);  
        }  
    }  
  
};  
  
  
  
template <class Derived> class state_machine;  
//默认的转发,实际上是一个初始值。   
struct default_event_dispatcher  
{  
    template<class FSM, class Event>  
    static int dispatch(  
        state_machine<FSM>& m, int state, Event const& e)  
    {  
        return m.call_no_transition(state, e);  
    }  
};  
  
  
template<class Table, class Event>  
struct generate_dispatcher;  
  
template<class Derived>  
class state_machine  
{  
    // ...   
protected:  
    template<  
        int CurrentState  
        , class Event  
        , int NextState  
        , void (*action)(Derived&, Event const&)  
    >  
    struct row  
    {  
        // for later use by our metaprogram   
        enum { current_state = CurrentState };  
        enum { next_state = NextState };  
        typedef Event event;  
        typedef Derived fsm_t;  
  
        // do the transition action.   
        static void execute(Derived& fsm, Event const& e)  
        {  
            (*action)(fsm, e);  
        }  
    };  
  
  
    friend struct default_event_dispatcher;  
  
    template <class Event>  
    int call_no_transition(int state, Event const& e)  
    {  
        return static_cast<Derived*>(this)->no_transition(state, e);  // CRTP downcast   
              
    }  
    //    
public:  
        template<class Event>  
    int process_event(Event const& evt)  
    {  
        // generate the dispatcher type.   
        typedef typename generate_dispatcher<  
            /*typename*/ Derived::transition_table, Event  
        >::type dispatcher;//相同的"Event"为一个row   
        
        // dispatch the event.   
        //这儿来递归的调用。对于相同的"Event",用state来区分。   
        this->state = dispatcher::dispatch(  
            *static_cast<Derived*>(this)        // CRTP downcast   
            , this->state  
            , evt  
            );  
  
        // return the new state   
        return this->state;  
    }  
  
    // ...   
protected:  
    state_machine()  
        : state(Derived::initial_state)  
    {  
    }  
  
private:  
    int state;  
    // ...   
  
    // ...   
public:  
    template <class Event>  
    int no_transition(int state, Event const& e)  
    {  
    //  assert(false);   
        return state;  
    }  
    // ...   
    ////   
};  
  
//在元编程中的固定写法。用类封装。   
template <class Event>   
struct is_same_event  
{  
    template <class Transition> struct apply  
        : boost::is_same<Event,typename Transition::event>  
    {//is_same比较两者类型是否相同,如果一者有const,另外一个没有const,这样算不同的类型。   
    };  
};  
//is_same_event比较"event"是否相同   
//filter_view,把相同的"event"存放在一起。   
//fold对相同的这些"event"调用方法。   
/* 
template<typename Sequence 
        ,typename State    
        ,typename ForwardOp     
        >struct fold 
{ 
    typedef unspecified type; 
}; 
描述持续调用二元 ForwardOp, 
以上一次调用 ForwardOp 所得结果(第一次调用时使用 State)和区间  
[begin<Sequence>::type, end<Sequence>::type) 的每个元素为参数, 
返回最终的结果。 
*/  
  
template<class Table, class Event>  
struct generate_dispatcher  
    : mpl::fold<  
    mpl::filter_view<   // select rows triggered by Event   
    Table  
    , is_same_event<Event>  
    >  
    , default_event_dispatcher  
    , event_dispatcher<_2,_1>   
    >  
{};  
//全例子最难的就是这个算法调用。上面的调用经过扩展,当参数是   
//open_close()的时候   
//event_dispatcher<state_machine<player>::row<4,open_close,1,&player::stop_and_open>,   
        //  event_dispatcher<state_machine<player>::row<3,open_close,1,&player::stop_and_open>,   
        //  event_dispatcher<state_machine<player>::row<0,open_close,1,&player::open_drawer>,   
        //  event_dispatcher<state_machine<player>::row<2,open_close,1,&player::open_drawer>,default_event_dispatcher>>>>   
//可以利用新建对象的方法来跟踪其类型。这是一个诀窍。   
  
struct play {};  
struct open_close {};  
struct cd_detected {   
    cd_detected(char const*, std::vector<clock_t> const&) {}  
};  
#ifdef __GNUC__ // in which pause seems to have a predefined meaning  
# define pause pause_  
#endif   
struct pause {};  
struct stop {};  
  
  
// concrete FSM implementation    
class player : public state_machine<player>  
{  
public:  
    // the list of FSM states   
    enum states {  
        Empty, Open, Stopped, Playing, Paused  
        , initial_state = Empty  
    };  
 
 
#ifdef __MWERKS__   
public: // Codewarrior bug workaround.  Tested at 0x3202  
#endif   
  
    static void start_playback(player&, play const&);  
    static void open_drawer(player&, open_close const&);  
    static void close_drawer(player&, open_close const&);  
    static void store_cd_info(player&, cd_detected const&);  
    static void stop_playback(player&, stop const&);  
    static void pause_playback(player&, pause const&);  
    static void resume_playback(player&, play const&);  
    static void stop_and_open(player&, open_close const&);  
 
 
#ifdef __MWERKS__   
private:  
#endif    
    friend class state_machine<player>;  
    typedef player p; // makes transition table cleaner   
  
    // transition table   
    struct transition_table : mpl::vector<  
  
        //    Start     Event         Next      Action   
        //  +---------+-------------+---------+------------------+   
        row < Stopped , play        , Playing , &start_playback  >,  
        row < Stopped , open_close  , Open    , &open_drawer     >,  
        //  +---------+-------------+---------+------------------+   
        row < Open    , open_close  , Empty   , &close_drawer    >,  
        //  +---------+-------------+---------+------------------+   
        row < Empty   , open_close  , Open    , &open_drawer     >,  
        row < Empty   , cd_detected , Stopped , &store_cd_info   >,  
        //  +---------+-------------+---------+------------------+   
        row < Playing , stop        , Stopped , &stop_playback   >,  
        row < Playing , pause       , Paused  , &pause_playback  >,  
        row < Playing , open_close  , Open    , &stop_and_open   >,  
        //  +---------+-------------+---------+------------------+   
        row < Paused  , play        , Playing , &resume_playback >,  
        row < Paused  , stop        , Stopped , &stop_playback   >,  
        row < Paused  , open_close  , Open    , &stop_and_open   >  
        //  +---------+-------------+---------+------------------+   
  
    > {};  
    typedef  
  
        event_dispatcher<  
        row<Stopped, play const, Playing, &start_playback>  
        , event_dispatcher<  
        row<Paused, play const, Playing, &resume_playback>  
        , default_event_dispatcher  
        >  
        >  
        dummy;  
};  
  
void player::start_playback(player&, play const&)  
{  
    std::cout<<"start_playback "<< std::endl;  
}  
  
void player::open_drawer(player&, open_close const&)  
{  
    std::cout<<"open_drawer "<< std::endl;  
}  
  
void player::close_drawer(player&, open_close const&)  
{  
    std::cout<<"close_drawer "<< std::endl;  
}  
void player::store_cd_info(player&, cd_detected const&)  
{  
    std::cout<<"store_cd_info "<< std::endl;  
}  
  
void player::stop_playback(player&, stop const&)  
{  
    std::cout<<"stop_playback "<< std::endl;  
}  
  
void player::pause_playback(player&, pause const&)  
{  
    std::cout<<"pause_playback "<< std::endl;  
}  
  
void player::resume_playback(player&, play const&)  
{  
    std::cout<<"resume_playback "<< std::endl;  
}  
  
void player::stop_and_open(player&, open_close const&)  
{  
    std::cout<<"stop_and_open "<<std::endl;  
}  
  
int _tmain(int argc, _TCHAR* argv[])  
{   
    player p;                      // An instance of the FSM   
  
    p.process_event(open_close()); // user opens CD player   
    p.process_event(open_close()); // inserts CD and closes   
    p.process_event(               // CD is detected   
        cd_detected(  
        "Louie, Louie"  
        , std::vector<clock_t>( /* track lengths */ )  
        )  
        );  
    p.process_event(play());       // etc.   
    p.process_event(pause());  
    p.process_event(play());  
    p.process_event(stop());  
  
    return 0;  
}
yshuise 2013-06-04
  • 打赏
  • 举报
回复
本人在csdn上与人PK的日子,真是值得怀念啊!
yshuise 2013-06-04
  • 打赏
  • 举报
回复
当年本人几乎穷尽所有C++书籍,可是到了今天差不多忘记了! BOOST是C++皇者的地位,想达到高水平,必须研究BOOST源码。 可以看我的博客:blog.csdn.net/yshuise,知道我不是在吹牛! 现在研究boost库的人越来越少,高手也越来越少。呵呵,可见我当年达到了何种地步!
赵4老师 2013-06-04
  • 打赏
  • 举报
回复
搜网络教程“学OpenGL编3D游戏”。
walker沃克 2013-06-04
  • 打赏
  • 举报
回复
看妹子的飘过。。。C++Primer习题解答。。。
  • 打赏
  • 举报
回复
绑定的路过~~~~~~~~
疯狂的红豆 2013-06-01
  • 打赏
  • 举报
回复
难度高于基础教材的一些C++代码 很少有的,网上的源码大多数是针对某个应用来的,某个领域来的,国外的sourceforge找找
漫步者、 2013-06-01
  • 打赏
  • 举报
回复
引用 3 楼 lhfslhfs 的回复:
[quote=引用 1 楼 ganpengjin1 的回复:] 网上下载C++项目源码看吧,这样学得快
什么样的源码?网址? [/quote] baidu.com
青松2 2013-06-01
  • 打赏
  • 举报
回复
引用 1 楼 ganpengjin1 的回复:
网上下载C++项目源码看吧,这样学得快
什么样的源码?网址?
qq120848369 2013-06-01
  • 打赏
  • 举报
回复
语言终究是语言,必须要和算法或者功能挂钩才有意思。
漫步者、 2013-06-01
  • 打赏
  • 举报
回复
网上下载C++项目源码看吧,这样学得快
飞天御剑流 2013-06-01
  • 打赏
  • 举报
回复
引用 楼主 lhfslhfs 的回复:
就是专门针对C++的编程例子,难度比C++基础教材上要大,规模也大,对例子解释比较详细的教材,有嘛?
给你个题目吧,实现文本编辑器的大文件缓冲,重点是发生添加删除时的处理策略。
加载更多回复(2)

64,636

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧