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

The Archive Base Latest Questions

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

So, I am willing to structure my project like that: ClassA.cpp: class ClassA {

  • 0

So, I am willing to structure my project like that:

ClassA.cpp:

class ClassA {
public:
    static ClassA* create() {
        return new ClassA();
    }
    void methodA() {
        // stuff here
    }
    void methodB() {
        // more stuff here
    }
private:
    ClassA() {
    }
    void privateMethodOne() {
        //yadda yadda
    }
    int attributeA;
    char attributeB;
};

ClassA.hpp:

class ClassA {
public:
    ClassA* create();
    void methodA();
    void methodB();
private:
    ClassA();
};

I am going to work only with pointers, I wonder if this approach would generate an error in a future. I wonder if there is a pitfall here. Suppose that the .hpp is automatically generated so it would have exactly the same members, except the private ones.

  • 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-27T20:58:12+00:00Added an answer on May 27, 2026 at 8:58 pm

    This approach is not valid. C++ has the one definition rule. See C++03 section 3.2 for full details, but here is Wikipedia’s summary (highlighting is mine):

    In short the ODR states that:

    1. In any translation unit, a template, type, function, or object can have no more than one definition. Some of these can have any number of declarations. A definition provides an instance.
    2. In the entire program, an object or non-inline function cannot have more than one definition; if an object or function is used, it must have exactly one definition. You can declare an object or function that is never used, in which case you don’t have to provide a definition. In no event can there be more than one definition.
    3. Some things, like types, templates, and extern inline functions, can be defined in more than one translation unit. For a given entity, each definition must be the same. Non-extern objects and functions in different translation units are different entities, even if their names and types are the same.

    You may be looking for the PIMPL idiom, which is a way to “hide” private members from the public interface (i.e. the public header file).

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

Sidebar

Related Questions

Our team is willing to unit-test a new code written under a running project
I have a directory structure in svn like this: Project A branches tags trunk
i would like to build a dynamic data structure that can hold a list
I have a table in a db that has a structure like this: Date
I'm willing to write program that after 5 sec shows text that was hidden
While I'm perfectly willing to believe that this has been asked elsewhere, I haven't
How can I create an xsd to give me this type of xml structure
I have 4 tables (appointed, class, elected, status) that I want to cross reference
I am willing to learn about different architectures of highly scalable web applications like
I have a web service that is willing to output gzip/deflated data. I've verified

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.