CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    38

    I need to stop executing constructor

    PHP Code:
    using namespace System;
    ref class A
    {
    public:
        
    A(){Console::WriteLine(L"A constructor");}
        
    virtual void func(){foo();}
        
    void foo()
        {
            
    Console::WriteLine(L"A from foo");
        }
    };
    ref class A_Mock:public A
    {
    public:
        
    virtual void func() override 
        
    {
            
    Console::WriteLine(L"A_MOCK");
        }
    };

    int main(array<System::String ^> ^args)
    {
        
    Console::WriteLine(L"Hello World");
        
    A^b=gcnew A_Mock();
        
    b->func();
        return 
    0;

    Supposing that class A is the development code; and so for unit-testing purpose I create a mock for it. But I don't know how to override A's constructor such that it will not get executed in my unit-test code.
    Thank you.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: I need to stop executing constructor

    What is this weird stuff?
    Code:
    int main(array<System::String ^> ^args)
    Seriously, you want the Managed C++ forum, not this one. There is no such keyword as "ref" in ANSI C++ or "gcnew", or any of the "^" stuff in the C++ language.

    This forum is for ANSI C++ using Visual C++, plus use of MFC, ATL libraries. Managed, CLR, or any type of .NET C++ goes in the Managed forum.

    Regards,

    Paul McKenzie

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured