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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:07:58+00:00 2026-05-11T01:07:58+00:00

Disclaimer Yes, I am fully aware that what I am asking about is totally

  • 0

Disclaimer

Yes, I am fully aware that what I am asking about is totally stupid and that anyone who would wish to try such a thing in production code should be fired and/or shot. I’m mainly looking to see if can be done.

Now that that’s out of the way, is there any way to access private class members in C++ from outside the class? For example, is there any way to do this with pointer offsets?

(Naive and otherwise non-production-ready techniques welcome)

Update

As noted in the comments, I asked this question because I wanted to write a blog post on over-encapsulation (and how it affects TDD). I wanted to see if there was a way to say "using private variables isn’t a 100% reliable way to enforce encapsulation, even in C++." At the end, I decided to focus more on how to solve the problem rather than why it’s a problem, so I didn’t feature some of the stuff brought up here as prominently as I had planned, but I still left a link.

At any rate, if anyone’s interested in how it came out, here it is: Enemies of Test Driven Development part I: encapsulation (I suggest reading it before you decide that I’m crazy).

  • 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. 2026-05-11T01:07:58+00:00Added an answer on May 11, 2026 at 1:07 am

    If the class contains any template member functions you can specialize that member function to suit your needs. Even if the original developer didn’t think of it.

    safe.h

    class safe {     int money;  public:     safe()      : money(1000000)     {     }      template <typename T>     void backdoor()     {         // Do some stuff.     } }; 

    main.cpp:

    #include <safe.h> #include <iostream>  class key;  template <> void safe::backdoor<key>() {     // My specialization.     money -= 100000;     std::cout << money << '\n'; }  int main() {     safe s;     s.backdoor<key>();     s.backdoor<key>(); } 

    Output:

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

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I bet this will work if you use a file://… May 11, 2026 at 10:10 am
  • added an answer I bet this Code Project page will get you headed… May 11, 2026 at 10:10 am
  • added an answer Welcome to the patterns & practices Team Development with Visual… May 11, 2026 at 10:10 am

Related Questions

Disclaimer Yes, I am fully aware that what I am asking about is totally
Disclaimer: This is not actually a programming question, but I feel the audience on
Disclaimer: I'm stuck on TFS and I hate it. My source control structure looks
Disclaimer: the following is a sin against XML. That's why I'm trying to change
Disclaimer: I'm fairly new to python! If I want all the lines of a
Disclaimer: This is for a homework assignment, but the question is not regarding the
DISCLAIMER: The following code is not something I would ever use in a real
Disclaimer This is not strictly a programming question, but most programmers soon or later
Full disclaimer: I'm a CS student, and this question is related to a recently

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.