首页
社区
课程
招聘
[原创]good morning world
发表于: 2013-8-19 05:40 2641

[原创]good morning world

2013-8-19 05:40
2641
code:
==========================================================
#include <iostream>
using namespace std;

class wordfirst
{
public:       
        virtual        void speak()=0;
};

struct wordsecond
{
   virtual void speak()=0;
};

class spkword :public wordfirst,wordsecond
{
        void wordfirst::speak()
        {
                cout<<"good morning world , I would !"<<endl;
        }
       
        void wordsecond::speak()
        {
                cout<<"早起的屌丝早日抱得女神归"<<endl;       
        }
};

int __cdecl main()
{
        spkword* sp;
        sp=new spkword;
        (reinterpret_cast<wordfirst*>(sp))->speak();
        (reinterpret_cast<wordsecond*>(sp))->speak();
        int i;
        cin>>i;
        return i;
}

==========================================================
facial expression

[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

收藏
免费 0
支持
分享
最新回复 (5)
雪    币: 101
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
today first c++ code , Pure Entertainment 2013.8.19.5.39.52
2013-8-19 05:45
0
雪    币: 31
活跃值: (43)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
3
老兄,加油~~~
2013-8-19 06:16
0
雪    币: 1392
活跃值: (4867)
能力值: ( LV13,RANK:240 )
在线值:
发帖
回帖
粉丝
4
illegal qualified name in member declaration VC6编译无法通过。

void wordfirst::speak() 这样的定义是非法的吧
2013-8-19 10:06
0
雪    币: 101
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
回楼上,早上有点想当然了,看编译通过了,就没看,也没调试
通过编译是没问题的,你看是不是哪抄错了,但是结果是错的,显示的都是第一个字符串
又认真重新写了一遍~~

#include <iostream>
#include <ObjBase.h>

using namespace std;

typedef int InterFaceIndex;

interface wordfirst :IUnknown
{
public:       
        virtual        void  __stdcall  speakf()=0;
};

interface wordsecond : IUnknown
{
public:
   virtual void  __stdcall  speaks()=0;
};

static const IID IID_Ifirst =
{0, 0, 0,
{0, 0, 0, 0, 0, 0, 0, 1}} ;

static const IID IID_Isecond =
{0, 0, 0,
{0, 0, 0, 0, 0, 0, 0, 2}} ;

class spkword :public wordfirst,public wordsecond
{
public:
        void __stdcall speakf()
        {
                cout<<"good morning world , I would !"<<endl;
        }

        void __stdcall speaks()
        {
                cout<<"早起的屌丝早日抱得女神归"<<endl;       
        }

        virtual HRESULT __stdcall spkword::QueryInterface(const IID& i,void** ppv)
        {
                if (i==IID_Ifirst)
                {
                        *ppv=static_cast<wordfirst*>(this);
                        return S_OK;
                }
                else if (i==IID_Isecond)
                {
                        *ppv=static_cast<wordsecond*>(this);
                        return S_OK;
                }
                else
                {
                        cout<<"index error"<<endl;
                        return E_NOINTERFACE;
                }
                return S_OK;
        }               

        virtual ULONG        __stdcall AddRef()        {        return        0;        }
        virtual ULONG        __stdcall Release()        {        return        0;        }
};

       

int __cdecl main()
{
        HRESULT hr;
        spkword* sp=new spkword;

        wordfirst* spf=NULL;
        if (SUCCEEDED( hr=sp->QueryInterface(IID_Ifirst,(void**)&spf)))
        {
                spf->speakf();
        }
       

        wordsecond* sps=NULL;
        if (SUCCEEDED( hr=sp->QueryInterface(IID_Isecond,(void**)&sps)))
        {
                sps->speaks();
        }

       
        int i;
        cin>>i;
        delete sp;
        return i;
}

上传的附件:
2013-8-19 12:21
0
雪    币: 101
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
VS2010+SDK7.1
2013-8-19 12:36
0
游客
登录 | 注册 方可回帖
返回
//