0

次のようなメインクラスがあります。

#include "stdafx.h"
using namespace std;

class MemoryAddressing : Memory {
    int _tmain(int argc, _TCHAR* argv[])
    {
        Memory mem;
        int hp = Memory.ReadOffset(0x000000);
    }
}

そして、2番目のクラスがあります:

#include <windows.h>
#include <iostream>

using namespace std;

static class Memory {
public : static int ReadOffset(DWORD offset) {
    DWORD address = 0x000000;
    DWORD pid;
    HWND hwnd;
    int value = 0;

    hwnd = FindWindow(NULL, L"");

    if(!hwnd) {
        cout << "error 01: Client not found, exiting...\n";
        Sleep(2000);
    }else {
        GetWindowThreadProcessId(hwnd, &pid);
        HANDLE handle = OpenProcess(PROCESS_VM_READ, 0, pid);
        if(!handle) {
            cout << "error 02: no permissions to read process";
        }
        else {
            ReadProcessMemory(handle, (void*) offset, &value,     sizeof(value), 0);
        }
    }
}
};

クラスのクラスReadOffsetからメソッドを継承しようとしていることは明らかです。方法がわかりません。クラスが通信できないようです。MemoryMemoryAddressing

私はすでに Java と C# を知っていますが、C++ は非常に異なると思います。

4

2 に答える 2

1

などの概念はありません。static class

クラスのデフォルトの継承はプライベートです。プライベート継承とは、関係がクラスのユーザーから隠されていることを意味します。使用することはめったにありませんが、少し集約に似ており、「の型である」というよりも、オブジェクト指向レベルで「の観点から実装されている」ことを意味します。

メソッド _tmain を呼び出すことはお勧めできませんが、何をしようとしているのでしょうか。メインをオーバーライドしますか?(または、クラスに static main メソッドがあり、エントリ ポイントとして実行可能にする Java をコピーしようとしています)。

于 2013-01-16T16:38:14.633 に答える
0

C++ ではstatic class動作しません。また、継承構文はオフです:

class MemoryAddressing : Memory {

する必要があります

class MemoryAddressing : public Memory {

In C++ クラスでは、:in 継承の後にアクセス修飾子が必要です。何も指定されていない場合は、デフォルトで になりprivateます。以下は、継承に関する C++ チュートリアルの章からの抜粋です。

In order to derive a class from another, we use a colon (:) in the declaration of the    
derived class using the following format:

class derived_class_name: public base_class_name
{ /*...*/ };

Where derived_class_name is the name of the derived class and base_class_name is the   
name of the class on which it is based. The public access specifier may be replaced by  
any one of the other access specifiers protected and private. This access specifier   
describes the minimum access level for the members that are inherited from the base   
class.

したがって、修飾子がないと、プライベート メンバーのみが継承されます。ただし、プライベート メンバーは派生クラスからアクセスできないため、本質class A : private B的に継承は発生しません。

于 2013-01-16T16:53:44.807 に答える