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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:25:16+00:00 2026-05-10T22:25:16+00:00

I’m an old (but not too old) Java programmer, that decided to learn C++.

  • 0

I’m an old (but not too old) Java programmer, that decided to learn C++. But I have seen that much of C++ programming style, is… well, just damn ugly!

All that stuff of putting the class definition in a header file, and the methods in a different source file- Calling functions out of nowhere, instead of using methods inside classes. All that just seems… wrong!

So finally, is there any reason for me to continue with this massacre to the OOP, and anything that is good and righteous in programming, or can I just ignore that old-fashioned C++ conventions, and use my good Java programing style?

By the way I’m learning C++, because I want to do game programing.

Here is an example:

In an C++ website I found a Windows implementation:

class WinClass {     public:          WinClass (WNDPROC wndProc, char const * className, HINSTANCE hInst);         void Register ()         {             ::RegisterClass (&_class);         }      private:          WNDCLASS _class; }; 

That class is located in a header file and the constructor:

WinClass::WinClass (WNDPROC wndProc, char const * className, HINSTANCE hInst) {     _class.style = 0;     _class.lpfnWndProc = wndProc;  // Window Procedure: mandatory     _class.cbClsExtra = 0;     _class.cbWndExtra = 0;     _class.hInstance = hInst;           // Owner of the class: mandatory     _class.hIcon = 0;     _class.hCursor = ::LoadCursor (0, IDC_ARROW); // Optional     _class.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); // Optional     _class.lpszMenuName = 0;     _class.lpszClassName = className;   // Mandatory } 

Is located at a .cpp source file.

What I could just do is:

class WinClass {     public:         WinClass (WNDPROC wndProc, char const * className, HINSTANCE hInst)         {             _class.style = 0;             _class.lpfnWndProc = wndProc;  // Window Procedure: mandatory             _class.cbClsExtra = 0;             _class.cbWndExtra = 0;             _class.hInstance = hInst;           // Owner of the class: mandatory             _class.hIcon = 0;             _class.hCursor = ::LoadCursor (0, IDC_ARROW); // Optional             _class.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); // Optional             _class.lpszMenuName = 0;             _class.lpszClassName = className;   // Mandatory         }          void Register ()         {             ::RegisterClass (&_class);         }      private:         WNDCLASS _class; }; 

And now the constructor is inside its class.

  • 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-10T22:25:17+00:00Added an answer on May 10, 2026 at 10:25 pm

    In addition to what others have said here, there are even more important problems:

    1) Large translation units lead to longer compile times and larger object file sizes.

    2) Circular dependencies! And this is the big one. And it can almost always be fixed by splitting up headers and source:

    // Vehicle.h class Wheel {     private:         Car& m_parent;     public:         Wheel( Car& p ) : m_parent( p ) {             std::cout << 'Car has ' << m_parent.numWheels() << ' wheels.' << std::endl;         } };  class Car {     private:         std::vector< Wheel > m_wheels;     public:         Car() {             for( int i=0; i<4; ++i )                 m_wheels.push_back( Wheel( *this ) );         }          int numWheels() {             return m_wheels.size();         } } 

    No matter what order you put these in, one will always be lacking the definition of the other, even using forward declarations it won’t work, since in the function bodies are using specifics about each class’s symbol.

    But if you split them up into proper .h and .cpp files and use forward declarations it will satisfy the compiler:

    //Wheel.h //------- class Car;  class Wheel { private:     Car& m_parent; public:     Wheel( Car& p ); };  //Wheel.cpp //--------- #include 'Wheel.h' #include 'Car.h'  Wheel::Wheel( Car& p ) : m_parent( p ) {         std::cout << 'Car has ' << m_parent.numWheels() << ' wheels.' << std::endl; }  //Car.h //----- class Wheel;  class Car { private:     std::vector< Wheel > m_wheels; public:     Car();     int numWheels(); }  //Car.cpp //------- #include 'Car.h' #include 'Wheel.h'  Car::Car() {         for( int i=0; i<4; ++i )             m_wheels.push_back( Wheel( *this ) ); }  int Car::numWheels() {         return m_wheels.size(); } 

    Now the code that actually has to know specifics about the second class can just include the header file which doesn’t need to know specifics about the first class.

    Headers just provide the declarations while source files provide the definitions. Or another way to say it: Headers tell you what is there (what symbols are valid to use) and source tells the compiler what the symbols actually do. In C++ you don’t need anything more than a valid symbol to begin using whatever it is.

    Trust that C++ has a reason for this idiom, because if you don’t you will make a lot of headaches for yourself down the line. I know :/

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

Sidebar

Ask A Question

Stats

  • Questions 51k
  • Answers 51k
  • 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 Use the if statement. I don't know what the overhead… May 11, 2026 at 6:24 am
  • added an answer Try following the directions here to make sure you're doing… May 11, 2026 at 6:24 am
  • added an answer There are a few different ways you can do the… May 11, 2026 at 6:24 am

Top Members

Trending Tags

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

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.