主类无法从我的第二个类继承方法
Main class can't inherit method from my second class
我的主类是这样的:
#include "stdafx.h"
using namespace std;
class MemoryAddressing : Memory {
int _tmain(int argc, _TCHAR* argv[])
{
Memory mem;
int hp = Memory.ReadOffset(0x000000);
}
}
然后是第二个类
#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);
}
}
}
};
很明显,我试图从我的Memory
类继承ReadOffset
方法在我的MemoryAddressing
类。我不知道如何,似乎类无法通信。
我已经知道Java和c#,但我认为c++是非常不同的。
没有static class
这个概念
类的默认继承是private。私有继承意味着对类的用户隐藏关系。它很少使用,但有点像聚合,意思是"按照"在面向对象级别上实现,而不是"是一种类型"。
不建议调用_tmain方法,但是你想做什么呢?覆盖主要吗?(或者您正在尝试复制Java,其中类具有静态主方法,使它们可作为入口点运行)。
在c++中static class
不起作用。你的继承语法也关闭了:
class MemoryAddressing : Memory {
应该class MemoryAddressing : public Memory {
c++中的类需要在继承中的:
之后添加访问修饰符。如果没有提供,则默认为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
基本上不会导致继承发生。
相关文章:
- 我有两个类需要在同一 cpp 文件中相互引用,但第一个类无法识别第二个类类型的对象
- 等待整个 omp 块完成,然后再调用第二个函数
- 我想在C++中读取一些多个字符,但它永远不会读取第二个字符
- 如何在创建自定义迭代器时获得 std::p air 的第一个和第二个?
- WinAPI 在单击第一个对话框上的按钮控件并销毁第一个对话框后创建第二个对话框
- 将第二个 GATT 服务添加到 Movesense 容器
- 如何在 c++ 中根据第二个元素按降序对列表进行排序
- 对的排序向量 (std::vector<pair<int, int>>) 按对的第一个元素搜索并更新第二个元素值
- 比较 2 个向量并从第二个向量中删除在第一个 - c++ 中找不到的元素
- 为什么这个程序没有打印返回的迭代器的正确第二个元素?
- 使第二个类的构造函数成为第一个类中的友元函数
- 为什么第二个代码给出了预期的结果,而第一个代码却没有?
- 为什么第一个代码块产生垃圾值,而第二个代码块将类成员的值相加?
- 打印无序映射的第二个元素,即集合
- 我有一个类,它创建了另一个类的实例.如何将变量通过第一个类传递到第二个类的实例化中?
- 需要使用模板查找数组的第二个最小和最小值
- c++:交换向量中所有元组的第一个和第二个元素
- 如果条件,当我想第二个参数时
- 将内容从第一个文件("constituencies")移动到第二个文件("temp")并在之后重命名时,我的文件被删除
- 主类无法从我的第二个类继承方法