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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:32:36+00:00 2026-05-30T21:32:36+00:00

I am confused on how to separate implementation and declarations code of a simple

  • 0

I am confused on how to separate implementation and declarations code of a simple class into a new header and cpp file. For example, how would I separate the code for the following class?

class A2DD
{
  private:
  int gx;
  int gy;

  public:
  A2DD(int x,int y)
  {
    gx = x;
    gy = y;
  }

  int getSum()
  {
    return gx + gy;
  }
};
  • 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-30T21:32:38+00:00Added an answer on May 30, 2026 at 9:32 pm

    The class declaration goes into the header file. It is important that you add the #ifndef include guards. Most compilers now also support #pragma once. Also I have omitted the private, by default C++ class members are private.

    // A2DD.h
    #ifndef A2DD_H
    #define A2DD_H
    
    class A2DD
    {
      int gx;
      int gy;
    
    public:
      A2DD(int x,int y);
      int getSum();
    
    };
    
    #endif
    

    and the implementation goes in the CPP file:

    // A2DD.cpp
    #include "A2DD.h"
    
    A2DD::A2DD(int x,int y)
    {
      gx = x;
      gy = y;
    }
    
    int A2DD::getSum()
    {
      return gx + gy;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very confused here, trying out the yuicompressor on a simple javascript file. My js
Cheers, I ran into this chunk of code in Programming Game AI by Example:
I'm confused as to why the following return separate sHA1s $ perl -MDigest::SHA1 -E'say
I am confused how directory name, file name and class name all work together.
The one class per file rule in Java has me a bit confused. I
How to separate this list into pieces in Python 2.6, I'm totally confused after
I am bringing out a separate question from here . It really confused me.
I'm getting confused with class inheritance for css. I have this: <ul id='grok'> <li
While designing the class, I always get confused what to put in Constructor and
Well, I`m confused about rails queries. For example: Affiche belongs_to :place Place has_many :affiches

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.