Skip to content

Instantly share code, notes, and snippets.

@sunmeat
Last active June 19, 2026 14:16
Show Gist options
  • Select an option

  • Save sunmeat/3cfee2182aabece572a7ab0f3615dabc to your computer and use it in GitHub Desktop.

Select an option

Save sunmeat/3cfee2182aabece572a7ab0f3615dabc to your computer and use it in GitHub Desktop.
будова об'єкта
#include <iostream>
#include <windows.h>
using namespace std;
class Dog {
public:
char* name; // 8 (якщо архітектура х64)
int age; // 4
void guard() {
cout << "Dog::Guard()\n";
}
void bark() {
cout << "Dog::Bark()\n";
}
static void print() {
cout << "Dog::Print()\n";
}
};
int main() {
cout << "Розмiр в байтах типу Dog: ";
cout << sizeof(Dog) << "\n"; // 16
Dog d;
cout << "Адреса об'єкту d типу Dog: ";
cout << &d << " (" << (long long int) & d << ")\n";
cout << "Адреса першого поля об'єкта d: ";
cout << &d.name << " (" << (long long int) & d.name << ")\n";
cout << "Адреса другого поля об'єкта d: ";
cout << &d.age << " (" << (long long int) & d.age << ")\n";
cout << "Адреса статичного методу класу Dog: ";
cout << &Dog::print << " (или ";
cout << &d.print << ")\n";
cout << "Адреса звичайного методу класу Dog: ";
void (Dog:: * memfunc_ptr)() = &Dog::bark;
auto cheat = &Dog::bark;
void* method_address = *(void**)(&memfunc_ptr);
cout << method_address << "\n";
Dog* dog = new Dog;
dog->bark();
(dog->*memfunc_ptr)();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment