Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6020711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:36:29+00:00 2026-05-23T03:36:29+00:00

I get a warning C4355: ‘this’ : used in base member initializer list from

  • 0

I get a warning C4355: 'this' : used in base member initializer list from Visual C++ 2010:

I have a class holding a handle, and I want to automatically close the handle even if the ctor for the class fails (so its dtor is not called). However, I don’t want to bother making a whole handle-wrapping class, and would rather hold it in a smart pointer. And so I wrote this:

foo.h
~~~~~
class Foo
{
    ...
    Log &_log;
    std::unique_ptr<void, std::function<void (void *)>> _handle;
    ...
}

foo.cpp
~~~~~~~
#include <windows.h>
Foo::Foo(Log &lg, ...) : _log(lg), ... _handle(nullptr, [&](void *h){ if (h) { if (!CloseHandle(h)) LOG(_log, "Could not close port: " << LastWinErr()); h = nullptr; } })
{
    HANDLE h(CreateFile( ...
    if (h == ...
    _handle.reset(h);
    ... // Bunch of other stuff that could potentially throw
}

Previously to the closure I was initializing _handle with something like _handle(nullptr, bind(PortDeleter, placeholders::_1, ref(_log))), but that requires a separate definition.

My questions: is the warning a concern for this specific instance? Either way, what is the detailed reason? Is there a trivial way to avoid it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:36:30+00:00Added an answer on May 23, 2026 at 3:36 am

    The short is, if you pass your this pointer around and it’s used to access member functions or variables in the initializer list or in the destructor, Bad Things Happen™. If you know that isn’t going to happen, then feel free to ignore the warning. Of course, it’s also a good warning- if any of the functions or variables that you access in the destructor belong to the class, then this is unsafe, as you may be accessing them prior to their construction/after their destruction. The problem is not critical if you know your initialization/destruction orders, but generally a bad move as this makes maintenance rather fiddly at best. As you could capture the constructor parameter instead, I’d have to recommend that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why do I get this warning in C# with Visual Studio 2010? Unreachable expression
I get this warning from GCC: warning: cannot pass objects of non-POD type 'class
Running FxCop on my code, I get this warning: Microsoft.Maintainability : 'FooBar.ctor is coupled
I'm using Chris Pederick's Firefox addon Web Developer 1.1.6 . I get this warning
With the Visual Studio 2005 C++ compiler , I get the following warning when
I have the following code, for which I get the error: Warning : mysqli_stmt::bind_result()
cell.image = [UIImage imageNamed:@search_up.png]; whenever i'm writing this statement i get warning like deprecated
When I run this bit of code through GCC I get this warning on
This is what i get: warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/usr/lib/info/dns.so (file
When I run mvn pmd:pmd I get an warning / error from PMD saying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.