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 8890499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:31:00+00:00 2026-06-14T22:31:00+00:00

I was writting a class for ‘turning’ modes on-off easily, then I got a

  • 0

I was writting a class for ‘turning’ modes on-off easily, then I got a bit confused. On the overloaded operator= to copy from another class, access to the private T member m_Modeis granted, why does this happen? Is it sandard, or perhaps a compiler bug?

template<class T>
class CFixedMode
{
private:
    T m_Mode;
public:
    CFixedMode()
    {
        m_Mode = static_cast<T>(0);
    }
    ~CFixedMode(){}
    void            SetMode( T mode );
    void            SetNotMode( T mode );
    BOOL            IsMode( T mode );
    CFixedMode<T>&              operator=( const CFixedMode< T >& rFixedMode );
};

template<class T>void CFixedMode<T>::SetMode( T mode )
{
    m_Mode |= mode;
}
template<class T>void CFixedMode<T>::SetNotMode( T mode )
{
    m_Mode &= (~mode);
}
template<class T>BOOL CFixedMode<T>::IsMode( T mode )
{
    return ( ( m_Mode & mode ) == mode ) ? TRUE : FALSE;
}
template<class T>CFixedMode<T>& CFixedMode<T>::operator =( const CFixedMode<T>& rFixedMode )
{
    if( typeid( m_Mode ) == typeid( rFixedMode.m_Mode ) )
        m_Mode = rFixedMode.m_Mode;
    return *this;
}

int _tmain(int argc, _TCHAR* argv[])
{
    CFixedMode<DWORD> Mode;
    DWORD rMode = 0x00000010;
    Mode.SetMode( rMode );

    CFixedMode<DWORD> Mode2;
    Mode2 = Mode;
    if( Mode2.IsMode( 0x00000010 ) )
    {
        //cout << Mode2.m_Mode; //c2248
        cout << "True" << endl;
    }

    typeid(Mode).before(typeid(CFixedMode<DWORD>));

    return 0;
}
  • 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-14T22:31:01+00:00Added an answer on June 14, 2026 at 10:31 pm

    Private means that it’s private to the class, not to instances of the class. Private is used to hide implementation details, so it makes sense that an object of the same type can access private members of other objects. Those other objects have the same implementation, so there’s no point in hiding details.

    By the way, your operator= should check for self assignment. (Or, as Chris pointed out, you could use the copy and swap idiom.) And, you don’t need to check the types with typeid.

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

Sidebar

Related Questions

I am writting a Python class with this constructor: #constuctor def __init__(self, initPt_=[1,1],fun_=Optim_tests.peaks,NITER_=30,alpha_=0.7,NMAX_=5000,FTOL_=10**(-10)): self.initPt
I am writting jnuit test case for testing API. my class is as follows
Consider I'm writting a static library. Let it has a class Foo // mylib.h
Scenerio - I am writting a web app that based off of which login
When writting class TemplateHandler, say I use TemplateHandler.h (for my the header) and TemplateHandler.cpp
I am currently writting a JNI wrapper for a C++ class and I'm not
I have the weirdest bug, when writting my LogHelper class. I am using org.osgi.service.log.LogService
In gcc I am writting friend class FriendMaker<T>::Type but Visual Studio wants friend FriendMaker<T>::Type
I'm writting my own view engine. public class MyViewEngine : RazorViewEngine { public override
Original Question I am writting a logging class where the goal is to be

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.