• 周四. 4月 25th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

all objects of the same class share the same set of class methods

admin

11月 28, 2021
#include <iostream> 
#include "First.h" 
  
void Test(); 
  
int main() 
{ 
    std::cerr<<"Error,Hello!"<<std::endl; 
  
    void (*p_Function)(void)=&Test; 
    for(size_t i=0;i<sizeof p_Function;i++) 
        printf("%d",reinterpret_cast<char *>(&p_Function)[i]); 
  
    std::cout<<"
"; 
  
    First first1,first2; 
    void (First::*p_Function_First_1)(void)=&First::Start; 
    void (First::*p_Function_First_2)(void)=&First::Start; 
    std::cout<<"First One:"<<std::endl; 
    for(size_t i=0;i<sizeof(p_Function_First_1);i++) 
        printf("%d",reinterpret_cast<char *>(&p_Function_First_1)[i]); 
    std::cout<<"
"; 
    std::cout<<"First Two:"<<std::endl; 
    for(size_t i=0;i<sizeof p_Function_First_2;i++) 
        printf("%d",reinterpret_cast<char *>(&p_Function_First_2)[i]); 
  
    getchar(); 
    return 0; 
} 

反映的是:
Each new object you create contains storage for its own internal variables, the class members.
But all objects of the same class share the same set of class methods, with just one copy of each
method.

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注