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. Managed C++/CLI
  4. __property oddity

__property oddity

Scheduled Pinned Locked Moved Managed C++/CLI
graphicshelp
24 Posts 6 Posters 125 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.
  • J James T Johnson

    Looking at MSDN it appears that all I need to do to create a property is prefix the Property name with get_ or set_ and put the __property keyword before the method (f.e. __property int get_Size() { return m_size; }) But when I do the same with my code, I get this error C2327: 'ScreenSaverUtils::OptimizedBitmap::Graphics' : member from enclosing class is not a type name, static, or enumerator Here is my code:

    __property Graphics* get_Graphics()
    {
    if( graphics == NULL )
    graphics = Graphics::FromHdc(hdc);

    return graphics;
    

    }

    Now if I just take out the __property keyword it compiles fine :confused: TIA, James Simplicity Rules!

    T Offline
    T Offline
    Tom Archer
    wrote on last edited by
    #7

    Did you solve this yet? I've got properties all over my code without a problem. Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

    N 1 Reply Last reply
    0
    • J James T Johnson

      Nope, just a single class; and returning the fully qualified name was the first thing I tried :-D I did rename the property from get_Graphics to get_Graphicsrrafsd and it works, even though I don't have a member named Graphics, so apparantly it doesn't like me having a property name the same as a class. What I don't understand is why not? I don't see any mention of this, and the closest thing was that you had to be explicit with types in the case of name clashes. James Simplicity Rules!

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #8

      James T. Johnson wrote: so apparantly it doesn't like me having a property name the same as a class. Isn't that the reason? I think even in C# you can't have a property named same as the class. Nish


      Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

      1 Reply Last reply
      0
      • T Tom Archer

        Did you solve this yet? I've got properties all over my code without a problem. Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #9

        Tom Archer wrote: Did you solve this yet? I've got properties all over my code without a problem. Tom, I think we cannot have properties named after the class. Nish


        Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

        J T 2 Replies Last reply
        0
        • N Nish Nishant

          Tom Archer wrote: Did you solve this yet? I've got properties all over my code without a problem. Tom, I think we cannot have properties named after the class. Nish


          Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #10

          You can have a property named after a class, just not the name of the class that contains it. This isn't my case, my class is named OptimizedBitmap. Refer to PaintEventArgs, it has a property named Graphics of type Graphics :) James Simplicity Rules!

          N 1 Reply Last reply
          0
          • J James T Johnson

            You can have a property named after a class, just not the name of the class that contains it. This isn't my case, my class is named OptimizedBitmap. Refer to PaintEventArgs, it has a property named Graphics of type Graphics :) James Simplicity Rules!

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #11

            Oops! Sorry James :( Nish


            Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

            J 1 Reply Last reply
            0
            • N Nish Nishant

              Tom Archer wrote: Did you solve this yet? I've got properties all over my code without a problem. Tom, I think we cannot have properties named after the class. Nish


              Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

              T Offline
              T Offline
              Tom Archer
              wrote on last edited by
              #12

              Actually, I copied the property into my code and it compiles fine sans the content. It's the content of the property that's the problem. I don't know if James has solved it or not. Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

              N 1 Reply Last reply
              0
              • N Nish Nishant

                Oops! Sorry James :( Nish


                Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                J Offline
                J Offline
                James T Johnson
                wrote on last edited by
                #13

                No problem :) I'm about to post my code so everyone can see whats going on. James Simplicity Rules!

                1 Reply Last reply
                0
                • J James T Johnson

                  Looking at MSDN it appears that all I need to do to create a property is prefix the Property name with get_ or set_ and put the __property keyword before the method (f.e. __property int get_Size() { return m_size; }) But when I do the same with my code, I get this error C2327: 'ScreenSaverUtils::OptimizedBitmap::Graphics' : member from enclosing class is not a type name, static, or enumerator Here is my code:

                  __property Graphics* get_Graphics()
                  {
                  if( graphics == NULL )
                  graphics = Graphics::FromHdc(hdc);

                  return graphics;
                  

                  }

                  Now if I just take out the __property keyword it compiles fine :confused: TIA, James Simplicity Rules!

                  J Offline
                  J Offline
                  James T Johnson
                  wrote on last edited by
                  #14

                  Here is the offending code

                  // ScreenSaverUtils.h

                  #pragma once

                  #pragma unmanaged
                  #include

                  #pragma managed

                  #using // For System.Diagnostics.Debug class

                  using namespace System;
                  using namespace System::Drawing;

                  namespace ScreenSaverUtils
                  {
                  public __gc class OptimizedBitmap : public IDisposable
                  {
                  private:
                  OptimizedBitmap(void)
                  {
                  }

                  public:
                  
                  	OptimizedBitmap(Graphics \*g, Bitmap \*bmpToCopy ) : \_disposed(false)
                  	{
                  		// Copy bitmap
                  	}
                  
                  	~OptimizedBitmap(void)
                  	{
                  		Dispose();
                  	}
                  
                  	void Dispose()
                  	{
                  		// Free resources
                  	}
                  
                  	\_\_property Graphics\* get\_Graphics()
                  	{
                  		System::Diagnostics::Debug::Assert(!\_disposed);
                  
                  		return Graphics::FromImage(bitmap);
                  	}
                  
                  	\_\_property Bitmap\* get\_Bitmap()
                  	{
                  		System::Diagnostics::Debug::Assert(!\_disposed);
                  
                  		return dynamic\_cast(bitmap->Clone());
                  	}
                  
                  private:
                  	bool \_disposed;
                  	HDC hdc;
                  	HBITMAP hbitmap;
                  	Graphics \*graphics;
                  	Bitmap \*bitmap;
                  };
                  

                  }

                  Thanks for everyone's help :) [Edit: I'm no longer interested in using those two as properties because the original intent has changed; but I still want to know why its failing to compile :)] James Simplicity Rules!

                  N 1 Reply Last reply
                  0
                  • T Tom Archer

                    Actually, I copied the property into my code and it compiles fine sans the content. It's the content of the property that's the problem. I don't know if James has solved it or not. Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                    N Offline
                    N Offline
                    Nish Nishant
                    wrote on last edited by
                    #15

                    Tom Archer wrote: I don't know if James has solved it or not. He hasnt. Not yet. I think he's going to post the code snippets now. Nish


                    Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                    T 1 Reply Last reply
                    0
                    • N Nish Nishant

                      Tom Archer wrote: I don't know if James has solved it or not. He hasnt. Not yet. I think he's going to post the code snippets now. Nish


                      Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

                      T Offline
                      T Offline
                      Tom Archer
                      wrote on last edited by
                      #16

                      Thanks, Nish. I saw that he had posted responses to other posts after I answered you. Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                      1 Reply Last reply
                      0
                      • J James T Johnson

                        Here is the offending code

                        // ScreenSaverUtils.h

                        #pragma once

                        #pragma unmanaged
                        #include

                        #pragma managed

                        #using // For System.Diagnostics.Debug class

                        using namespace System;
                        using namespace System::Drawing;

                        namespace ScreenSaverUtils
                        {
                        public __gc class OptimizedBitmap : public IDisposable
                        {
                        private:
                        OptimizedBitmap(void)
                        {
                        }

                        public:
                        
                        	OptimizedBitmap(Graphics \*g, Bitmap \*bmpToCopy ) : \_disposed(false)
                        	{
                        		// Copy bitmap
                        	}
                        
                        	~OptimizedBitmap(void)
                        	{
                        		Dispose();
                        	}
                        
                        	void Dispose()
                        	{
                        		// Free resources
                        	}
                        
                        	\_\_property Graphics\* get\_Graphics()
                        	{
                        		System::Diagnostics::Debug::Assert(!\_disposed);
                        
                        		return Graphics::FromImage(bitmap);
                        	}
                        
                        	\_\_property Bitmap\* get\_Bitmap()
                        	{
                        		System::Diagnostics::Debug::Assert(!\_disposed);
                        
                        		return dynamic\_cast(bitmap->Clone());
                        	}
                        
                        private:
                        	bool \_disposed;
                        	HDC hdc;
                        	HBITMAP hbitmap;
                        	Graphics \*graphics;
                        	Bitmap \*bitmap;
                        };
                        

                        }

                        Thanks for everyone's help :) [Edit: I'm no longer interested in using those two as properties because the original intent has changed; but I still want to know why its failing to compile :)] James Simplicity Rules!

                        N Offline
                        N Offline
                        Neil Van Note
                        wrote on last edited by
                        #17

                        Actually, depending on how you arrange this code, it comes back with varying results. If you move the variable declarations to the top of the class, most of the problems disappear. This doesn’t give me a whole lot of faith in MC++. There seems to be a conflict here though, but nothing is jumping out at me as anything being wrong with the class structure. Note: Variable names should not start with an underscore in C/C++; those are reserved for compiler vendors. The following compiles.

                        public __gc class OptimizedBitmap : public IDisposable
                        {
                        private:
                        bool disposed;
                        HDC hdc;
                        HBITMAP hbitmap;
                        Graphics *graphics;
                        Bitmap *bitmap;

                        OptimizedBitmap()
                        {
                        }
                        

                        public:
                        OptimizedBitmap(Graphics *g, Bitmap *bmpToCopy ) :
                        disposed(false)
                        {
                        // Copy bitmap
                        }
                        ~OptimizedBitmap(void)
                        {
                        Dispose();
                        }
                        void Dispose() {
                        // Free resources
                        }
                        __property Graphics* get_Graphics()
                        {
                        return Graphics::FromImage(bitmap);
                        }
                        __property Bitmap* get_Bitmap()
                        {
                        #if 0
                        return dynamic_castSystem::Drawing::Bitmap\*(bitmap->Clone());
                        #else // or
                        return new System::Drawing::Bitmap(bitmap);
                        #endif
                        }
                        };

                        J 1 Reply Last reply
                        0
                        • N Neil Van Note

                          Actually, depending on how you arrange this code, it comes back with varying results. If you move the variable declarations to the top of the class, most of the problems disappear. This doesn’t give me a whole lot of faith in MC++. There seems to be a conflict here though, but nothing is jumping out at me as anything being wrong with the class structure. Note: Variable names should not start with an underscore in C/C++; those are reserved for compiler vendors. The following compiles.

                          public __gc class OptimizedBitmap : public IDisposable
                          {
                          private:
                          bool disposed;
                          HDC hdc;
                          HBITMAP hbitmap;
                          Graphics *graphics;
                          Bitmap *bitmap;

                          OptimizedBitmap()
                          {
                          }
                          

                          public:
                          OptimizedBitmap(Graphics *g, Bitmap *bmpToCopy ) :
                          disposed(false)
                          {
                          // Copy bitmap
                          }
                          ~OptimizedBitmap(void)
                          {
                          Dispose();
                          }
                          void Dispose() {
                          // Free resources
                          }
                          __property Graphics* get_Graphics()
                          {
                          return Graphics::FromImage(bitmap);
                          }
                          __property Bitmap* get_Bitmap()
                          {
                          #if 0
                          return dynamic_castSystem::Drawing::Bitmap\*(bitmap->Clone());
                          #else // or
                          return new System::Drawing::Bitmap(bitmap);
                          #endif
                          }
                          };

                          J Offline
                          J Offline
                          James T Johnson
                          wrote on last edited by
                          #18

                          Thanks Neil, i'll put this through its run later, but now I have some anime to watch :) James Simplicity Rules!

                          N 1 Reply Last reply
                          0
                          • J James T Johnson

                            Thanks Neil, i'll put this through its run later, but now I have some anime to watch :) James Simplicity Rules!

                            N Offline
                            N Offline
                            Neil Van Note
                            wrote on last edited by
                            #19

                            This is interesting, I just created a new project and found this... This compiles...

                            namespace VNK {

                            using namespace System;
                            using namespace System::Drawing;

                            public __gc class Foo
                            {
                            private:
                            Graphics *m_pGraphics;
                            Bitmap *m_pBitmap;

                            public:
                            Foo();
                            ~Foo();

                            \_\_property Graphics\* get\_Graphics()
                            {
                            	return m\_pGraphics;
                            }
                            \_\_property Bitmap\* get\_Bitmap()
                            {
                            	return m\_pBitmap;
                            }
                            

                            };

                            This does not...

                            namespace VNK {

                            using namespace System;
                            using namespace System::Drawing;

                            public __gc class Foo
                            {
                            public:
                            Foo();
                            ~Foo();

                            \_\_property Graphics\* get\_Graphics()
                            {
                            	return m\_pGraphics;
                            }
                            \_\_property Bitmap\* get\_Bitmap()
                            {
                            	return m\_pBitmap;
                            }
                            

                            private:
                            Graphics *m_pGraphics;
                            Bitmap *m_pBitmap;
                            };

                            I would bet there is a bug report on this, or I am missing something very fundamental that came in on the heals of MC++.

                            T R 2 Replies Last reply
                            0
                            • N Neil Van Note

                              This is interesting, I just created a new project and found this... This compiles...

                              namespace VNK {

                              using namespace System;
                              using namespace System::Drawing;

                              public __gc class Foo
                              {
                              private:
                              Graphics *m_pGraphics;
                              Bitmap *m_pBitmap;

                              public:
                              Foo();
                              ~Foo();

                              \_\_property Graphics\* get\_Graphics()
                              {
                              	return m\_pGraphics;
                              }
                              \_\_property Bitmap\* get\_Bitmap()
                              {
                              	return m\_pBitmap;
                              }
                              

                              };

                              This does not...

                              namespace VNK {

                              using namespace System;
                              using namespace System::Drawing;

                              public __gc class Foo
                              {
                              public:
                              Foo();
                              ~Foo();

                              \_\_property Graphics\* get\_Graphics()
                              {
                              	return m\_pGraphics;
                              }
                              \_\_property Bitmap\* get\_Bitmap()
                              {
                              	return m\_pBitmap;
                              }
                              

                              private:
                              Graphics *m_pGraphics;
                              Bitmap *m_pBitmap;
                              };

                              I would bet there is a bug report on this, or I am missing something very fundamental that came in on the heals of MC++.

                              T Offline
                              T Offline
                              Tom Archer
                              wrote on last edited by
                              #20

                              That would explain why it worked on my machine then. Very strange... Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                              J 1 Reply Last reply
                              0
                              • N Neil Van Note

                                This is interesting, I just created a new project and found this... This compiles...

                                namespace VNK {

                                using namespace System;
                                using namespace System::Drawing;

                                public __gc class Foo
                                {
                                private:
                                Graphics *m_pGraphics;
                                Bitmap *m_pBitmap;

                                public:
                                Foo();
                                ~Foo();

                                \_\_property Graphics\* get\_Graphics()
                                {
                                	return m\_pGraphics;
                                }
                                \_\_property Bitmap\* get\_Bitmap()
                                {
                                	return m\_pBitmap;
                                }
                                

                                };

                                This does not...

                                namespace VNK {

                                using namespace System;
                                using namespace System::Drawing;

                                public __gc class Foo
                                {
                                public:
                                Foo();
                                ~Foo();

                                \_\_property Graphics\* get\_Graphics()
                                {
                                	return m\_pGraphics;
                                }
                                \_\_property Bitmap\* get\_Bitmap()
                                {
                                	return m\_pBitmap;
                                }
                                

                                private:
                                Graphics *m_pGraphics;
                                Bitmap *m_pBitmap;
                                };

                                I would bet there is a bug report on this, or I am missing something very fundamental that came in on the heals of MC++.

                                R Offline
                                R Offline
                                Rama Krishna Vavilala
                                wrote on last edited by
                                #21

                                I don't think it's a bug. To me it is looks quite obvious that the scope resolution should fail in the second case as it tries to resolve the token Graphics in the local scope and it turns out to be a property name where property name is not expected. Solve this using

                                using namespace System;
                                using namespace System::Drawing;
                                public \_\_gc class Foo
                                {
                                	public:	
                                		Foo();	
                                		~Foo();	
                                		
                                		\_\_property Graphics\* get\_Graphics()	
                                		{		
                                			return m\_pGraphics;	
                                		}	
                                		\_\_property Bitmap\* get\_Bitmap()	
                                		{		
                                			return m\_pBitmap;	
                                		}
                                private:	
                                	System::Drawing::Graphics \*m\_pGraphics;	
                                	System::Drawing::Bitmap   \*m\_pBitmap;
                                };
                                

                                And for all the C# haters, C# compiler is much smarter in this regard.

                                J N 2 Replies Last reply
                                0
                                • T Tom Archer

                                  That would explain why it worked on my machine then. Very strange... Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.

                                  J Offline
                                  J Offline
                                  James T Johnson
                                  wrote on last edited by
                                  #22

                                  Tom Archer wrote: Very strange... It is indeed, before Christian tore me away from my research, I didn't see anything that would indicate variable declarations need to go at the top of the file. Unfortunately all the __property examples I've seen use the same one slightly modified: __property int get_Size() { return 0; } __property void set_Size() { } X| Once I get my mind back in shape I'll take a further look :) James Simplicity Rules!

                                  1 Reply Last reply
                                  0
                                  • R Rama Krishna Vavilala

                                    I don't think it's a bug. To me it is looks quite obvious that the scope resolution should fail in the second case as it tries to resolve the token Graphics in the local scope and it turns out to be a property name where property name is not expected. Solve this using

                                    using namespace System;
                                    using namespace System::Drawing;
                                    public \_\_gc class Foo
                                    {
                                    	public:	
                                    		Foo();	
                                    		~Foo();	
                                    		
                                    		\_\_property Graphics\* get\_Graphics()	
                                    		{		
                                    			return m\_pGraphics;	
                                    		}	
                                    		\_\_property Bitmap\* get\_Bitmap()	
                                    		{		
                                    			return m\_pBitmap;	
                                    		}
                                    private:	
                                    	System::Drawing::Graphics \*m\_pGraphics;	
                                    	System::Drawing::Bitmap   \*m\_pBitmap;
                                    };
                                    

                                    And for all the C# haters, C# compiler is much smarter in this regard.

                                    J Offline
                                    J Offline
                                    James T Johnson
                                    wrote on last edited by
                                    #23

                                    Rama Krishna wrote: private: System::Drawing::Graphics *m_pGraphics; System::Drawing::Bitmap *m_pBitmap; :omg: :omg: Thats it, I quit! ;P James Simplicity Rules!

                                    1 Reply Last reply
                                    0
                                    • R Rama Krishna Vavilala

                                      I don't think it's a bug. To me it is looks quite obvious that the scope resolution should fail in the second case as it tries to resolve the token Graphics in the local scope and it turns out to be a property name where property name is not expected. Solve this using

                                      using namespace System;
                                      using namespace System::Drawing;
                                      public \_\_gc class Foo
                                      {
                                      	public:	
                                      		Foo();	
                                      		~Foo();	
                                      		
                                      		\_\_property Graphics\* get\_Graphics()	
                                      		{		
                                      			return m\_pGraphics;	
                                      		}	
                                      		\_\_property Bitmap\* get\_Bitmap()	
                                      		{		
                                      			return m\_pBitmap;	
                                      		}
                                      private:	
                                      	System::Drawing::Graphics \*m\_pGraphics;	
                                      	System::Drawing::Bitmap   \*m\_pBitmap;
                                      };
                                      

                                      And for all the C# haters, C# compiler is much smarter in this regard.

                                      N Offline
                                      N Offline
                                      Neil Van Note
                                      wrote on last edited by
                                      #24

                                      Actually, I think you may be correct, that’s what I get for looking at these things at 3:30 in the morning...

                                      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