[RESOLVED] Forms SingleTon VC++2010?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [RESOLVED] Forms SingleTon VC++2010?

  1. #1
    Join Date
    Dec 2011
    Posts
    53

    [RESOLVED] Forms SingleTon VC++2010?

    Hi,
    Iam using the below code for forms singleton in c#.. When I convert it to VC++ its giving error..
    c# code
    ======
    private static Form2 _instance = null;
    public static Form2 GetForm (bool IsMDIChild, Form1 frm)
    {
    if (_instance == null)
    _instance = new Form2();

    if (_instance.IsDisposed)
    _instance = new Form2();

    if (IsMDIChild)
    _instance.MdiParent = frm;

    return _instance;
    }

    I convert it like a below.. to vc++2010
    ===========================

    public: static Form2^ Form2::_instance = nullptr;

    public: static Form2^ Form2::GetForm(bool IsMDIChild, Form1^ MyInstFrm) {
    if (_instance == nullptr)
    _instance = gcnew Form2();

    if (_instance->IsDisposed)
    _instance = gcnew Form2();

    if (IsMDIChild)
    _instance->MdiParent = MyInstFrm;

    return _instance;
    }

    But its giving below error

    01. Error c2061 Syntax error : Identifier 'Form1'

    Thanks

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,585

    Re: Forms SingleTon VC++2010?

    Perhaps you forgot to #include "Form1.h", so Form1 isn't defined at that point?

    EDIT: I noticed that actually you're not using any members specific to Form1 at all anyway in that code, so you may as well change the type of that parameter to Form ^, so the include wouldn't be needed. You could still pass an instance of any class derived from Form to that parameter.

    Please use code tags when posting code.
    Last edited by Eri523; April 22nd, 2012 at 06:11 PM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Dec 2011
    Posts
    53

    Re: Forms SingleTon VC++2010?

    My Heartiest Thanks To ERI...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center