Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Static object in mfc, only one instance for all instance of my class

Static object in mfc, only one instance for all instance of my class

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++javacomgraphics
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Remi Morin
    wrote on last edited by
    #1

    Hi, My Class is using some bitmap, there not very big I'd like that only one instance of the bitmap exist for all instance of my class. In java it's static member of the class, in MFC I've try to do Class MyClass: public CWnd { ...blablabla... private: static CBitmap MyBitmap; ...blablabla } and the linker said MyClass.obj :error LNK2001:unresolved external symbol "private: static class CBitmap MyClass::MyBitmap" (?MyBitmap@MyClass@@0VCBitmap@@A) so what is wrong? Remi Morin Rmorin@Operamail.com Remi.Morin@Lyrtech.com

    C 1 Reply Last reply
    0
    • R Remi Morin

      Hi, My Class is using some bitmap, there not very big I'd like that only one instance of the bitmap exist for all instance of my class. In java it's static member of the class, in MFC I've try to do Class MyClass: public CWnd { ...blablabla... private: static CBitmap MyBitmap; ...blablabla } and the linker said MyClass.obj :error LNK2001:unresolved external symbol "private: static class CBitmap MyClass::MyBitmap" (?MyBitmap@MyClass@@0VCBitmap@@A) so what is wrong? Remi Morin Rmorin@Operamail.com Remi.Morin@Lyrtech.com

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      in a .cpp file, you need to have:

      #include "MyClass.h"

      // declare the variable
      CBitmap myClass::MyBitmap;

      -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com

      R 1 Reply Last reply
      0
      • C Chris Losinger

        in a .cpp file, you need to have:

        #include "MyClass.h"

        // declare the variable
        CBitmap myClass::MyBitmap;

        -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com

        R Offline
        R Offline
        Remi Morin
        wrote on last edited by
        #3

        thanks, it was easy;) Remi Morin Rmorin@Operamail.com Remi.Morin@Lyrtech.com

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups