Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. LIBCACHE.H
  2.  
  3. #pragma once
  4.  
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8.  
  9. typedef struct Cache Cache;
  10.  
  11. int CreateCache(Cache *cache);
  12. int DestroyCache(Cache *cache);
  13.  
  14. #ifdef __cplusplus
  15. }
  16. #endif
  17.  
  18.  
  19. CACHE.CPP
  20.  
  21. #include "libcache.h"
  22.  
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26.     int CreateCache(Cache *cache)
  27.     {
  28.         std::cout << "AAA: " << cache << std::endl;
  29.         cache = new Cache();
  30.         std::cout << "BBB: " << cache << std::endl;
  31.         return 0;
  32.     }
  33.  
  34.     int DestroyCache(Cache *cache)
  35.     {
  36.         delete cache;
  37.         cache = NULL;
  38.         return 0;
  39.     }
  40. #ifdef __cplusplus
  41. }
  42. #endif
  43.  
  44. MAIN.C
  45.  
  46. int main(int argc, char *argv[])
  47. {
  48.     Cache *cache = NULL;
  49.     CreateCache(cache);
  50.     printf("%s - %p\n", "Cache created", cache);
  51.     //DestroyCache(cache);
  52.     printf("%s - %p\n", "Cache destroyed", cache);
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement