Initiate member variable??

Login to reply to this topic.
Tue, 2007-10-09 14:32
Joined: 2007-06-30
Forum posts: 7

I define a TInt variable in .h file,and initiate it in default Construct function,the code as below:
in CImageDecode.h defining a variable:

        TInt m_nWidth;

in cpp,initiate the variable m_nWidth
        CImageDecode :: CImageDecode (CAppController& aController)
        :CActive( CActive::EPriorityStandard ),
          iController( aController ),
          m_nWidth(0)
        {
                   CActiveScheduler::Add( this );
        }

and then in the GetImageWidth() function:
        TInt CImageDecode:: GetImageWidth()
        {
            m_nWidth = 10;
            return m_nWidth;     //The Application crash here and exit
        }

But when I define variable like this:
        TInt CImageDecode:: GetImageWidth()
        {
            TInt m_nWidth = 10;
            return m_nWidth;    
        }

it Works very well.

I cann't understand why. Can somebody get me out?
Thanks in advance.


Tue, 2007-10-09 15:02
Joined: 2004-05-24
Forum posts: 982
Re: Initiate member variable??

Are you sure in your first case is TInt and not TInt* ?
Also can you let us know what error do you het there? (when app crashes)


pirosl

Tue, 2007-10-09 15:14
Joined: 2007-06-30
Forum posts: 7
Re: Initiate member variable??

pirosl,Thanks for your quick reply.

Yes,I am sure it is TInt not TInt*.

and I don't know how to catch the error code when it crashes.
Because I run the app on the phone.
And can you guide me how to catch the error code?

Tue, 2007-10-09 16:06
Joined: 2007-09-12
Forum posts: 8
Re: Initiate member variable??

Are you sure by the time you call GetImageWidth(), your CImageDecode object is not deleted (and maybe set to NULL)?

Tue, 2007-10-09 16:54
Joined: 2004-05-24
Forum posts: 982
Re: Initiate member variable??

Can you share the h and cpp file?


pirosl

Tue, 2007-10-09 21:24
Joined: 2007-09-23
Forum posts: 159
Re: Initiate member variable??

If its a member variable why doesn't it begin with i like iController does?

Lets see how you create its parent object before you use it. I hope you're not doing something daft like
CImageDecode* decode;
decode->GetImageWidth();

Tue, 2007-10-09 20:37
Joined: 2003-12-05
Forum posts: 672
Re: Initiate member variable??

Set a breakpoint in the method and check out the value of this pointer. Is it valid?

  • Login to reply to this topic.