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

  • SEARCH
  • Home
  • 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 7997887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:04:35+00:00 2026-06-04T15:04:35+00:00

Imagine i have such library: Library.h class DLLEXPORT LibraryClass { private: int _id; static

  • 0

Imagine i have such library:

Library.h

   class DLLEXPORT LibraryClass
    {
    private:
      int _id;
      static int _last_id;
    public:
      LibraryClass();
      bool operator == (const LibraryClass t)
      {return _id == t._id;}
    };

Library.cpp

#include "Library.h"

int LibraryClass::_last_id = 0;

LibraryClass::LibraryClass()
_id(_last_id)
{
++_last_id;
}

Will it work correct? I’m getting C4835 warning in Visual Studio, but seems it works. Does anybody know how it will work on other compilers (i’m interested in linux gcc and mac gcc)? Is there another “valid” implementation for such pattern?

  • 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-06-04T15:04:38+00:00Added an answer on June 4, 2026 at 3:04 pm

    Your syntax is fine and this shouldn’t cause any issues in your code; I don’t think you’d see any warnings on a UNIX/MAC system while compiling this (except for the fact that you’re doing a DLL export which is windows oriented). I belive you’re just seeing fallout of managed C++.

    From MSDN:

    ‘variable’ : the initializer for exported data will not be run until
    managed code is first executed in the host assembly

    When accessing data between managed components, it is recommended that
    you not use native C++ import and export mechanisms. Instead, declare
    your data members inside a managed type and reference the metadata
    with #using in the client. For more information, see #using Directive
    (C/C++).

    Your static data member will be in the initialized test segment of your program when compiled on unix. It is guaranteed to be initialized to the value you provided prior to execution, so it will start at 0, and it will be completely usable in your constructor by the time it is invoked.

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

Sidebar

Related Questions

Imagine I have such class hierarchy: Base A : Base B : Base C
Imagine I have a method: void Method(bool parameter){ if(parameter){ // first case } else
Imagine I have these columns in a table: id int NOT NULL IDENTITY PRIMARY
Imagine I have a C++ class Foo and a class Bar which has to
Imagine I have a service that looks like this: public interface MyAccountService { boolean
Imagine an HTML form and the jQuery library is loaded. I'd like it such
Imagine you have a derived class, where the base class is something you cannot
We have a class library, written in Java (Standard Edition or MIDP 2.0, we
Imagine I have a method having a contract : public void Do(string value) {
Imagine I have a class used to represent some trivial numerical data, like a

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.