locked
class inside of class RRS feed

  • Question

  • hi i want know if this is writed good

    namespace boz
    {
    	ref class Toolbox : System::Windows::Forms::TreeView
    	{
    	ref class TBTreeNode : System::Windows::Forms::TreeNode
    	{
    	private: 
    		String ^ mTooltipCaption;
    	private: bool mOnEdit;
    	private: bool mEnabled;
    
    	public:
    		property String^ ToolTipCaption
    		{
    			 String^ get()
    			{
    				return this->mTooltipCaption;
    			}
    			
    		}
    	public:
    		property bool OnEdit
    		{
    			bool get()
    			{
    				return this->mOnEdit;
    			}
    		
    		}
    	public:
    		property bool Enabled
    		{
    			bool get()
    			{
    				return this->mEnabled;
    			}
    		}
    
    
    
    			 TBTreeNode(int const mToolTipCaption, int const mOnEdit, int const mEnabled)
    			 {
    				 this->mToolTipCaption  = String::Empty;
    				 this->mOnEdit			= false;
    				 this->mOnEnabled		= true;
    			 }
    
    			 ~TBTreeNode()
    			 {
    				 
    			 }
    
    
    	}
    the lines of the constructor say me that these this statements not are member of the class how i fix it?
    Saturday, November 14, 2009 6:28 PM

Answers

  • You have two options there. The first is to make TVS_NOTOOLTIPS static (which is definitely the preferred option; there's no point in making each instance of your class have its own data member for something that will never change between instances), in which case inline initialization works as you've tried to do:

    ref class MyClass
    {
        static int const TVS_NOTOOLTIPS = 0x80;
    };


    The other option is to leave it non-static, and initialize it in the constructor's initialization list:

    ref class MyClass
    {
        int const TVS_NOTOOLTIPS;
    
    public:
        MyClass() :
            TVS_NOTOOLTIPS(0x80)
        { }
    };

    Monday, November 16, 2009 3:12 AM

All replies

  • Try this:

    namespace boz
    {
        ref class Toolbox : System::Windows::Forms::TreeView
        {
            ref class TBTreeNode : System::Windows::Forms::TreeNode
            {
                String^ mTooltipCaption;
                bool mOnEdit;
                bool mEnabled;
    
            public:
                property String^ ToolTipCaption
                {
                    String^ get()
                    {
                        return mTooltipCaption;
                    }
                }
    
                property bool OnEdit
                {
                    bool get()
                    {
                        return mOnEdit;
                    }
                }
    
                property bool Enabled
                {
                    bool get()
                    {
                        return mEnabled;
                    }
                }
    
                TBTreeNode() :
                    mTooltipCaption(String::Empty),
                    mOnEdit(false),
                    mEnabled(true)
                { }
            }
        }
    }

    Note that ~TBTreeNode is not a destructor, but in fact implements IDisposable. See http://msdn.microsoft.com/en-us/library/ms177197.aspx for more information.
    Saturday, November 14, 2009 6:46 PM
  • thanks
    i forget say that this is code C++/CLI

    and with this how i do?

    private: const int TVS_NOTOOLTIPS = 0x80;

    says error of syntax

    ia m looking for in the web but i can`t find look like
    Monday, November 16, 2009 2:48 AM
  • You have two options there. The first is to make TVS_NOTOOLTIPS static (which is definitely the preferred option; there's no point in making each instance of your class have its own data member for something that will never change between instances), in which case inline initialization works as you've tried to do:

    ref class MyClass
    {
        static int const TVS_NOTOOLTIPS = 0x80;
    };


    The other option is to leave it non-static, and initialize it in the constructor's initialization list:

    ref class MyClass
    {
        int const TVS_NOTOOLTIPS;
    
    public:
        MyClass() :
            TVS_NOTOOLTIPS(0x80)
        { }
    };

    Monday, November 16, 2009 3:12 AM