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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:55:32+00:00 2026-05-18T09:55:32+00:00

I have programmed a bit of C++ back about 14 years ago. I got

  • 0

I have programmed a bit of C++ back about 14 years ago. I got acquainted to new technologies such as .NET with which I work mostly work with.

Now, I’m writing a simlpe phone list Windows Application which I want to make it C++ so that I can better view C# and C++ differences.

Let me say that I have already noticed a difference! Hehehe… Hence, one of those difference is that when creating a new C++ class from Visual Studio template, it creates not only the .cpp class file, but also a header file along with it.

Why is that so? Why creating a class1.h and a class1.cpp files for one classe?

I remember that header files are likely libraries of functions and objects, if we may say so, for future reuse, do I remember correctly?

Questions

  1. Why are there two files (.h and .cpp) created when adding a new C++ class?
  2. Should I define the members in the header file and define the functions core in the cpp file?
  3. If no to 2, what is the header file for in this particular scenario?

EDIT #1

Then should my code look like this?

// Customer.h header file
ref class Customer {
    private:
        char* _number, _name;
        long _phoneNumber;

    public:
        char[] get_number();
        void set_number(char* number);
        char[] get_name();
        void set_name(char* name);
        long get_phoneNumber();
        void set_phoneNumber(long phoneNumber);
        void set_name(char* name);
}

Then:

// Customer.cpp
#include <Customer.h>

char[] Customer::get_number() {
    return _number;
}

void Customer::set_number(char* number) {
    if (number != null && sizeof(number) < 1) return;
    _number = number;
}

// And the other members here...

Now I know, there most be plenty of errors in my code. I’ll be happy if you help me correct them so that I can improve my C++ skills.

Thanks for helping me figuring it out.

  • 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-18T09:55:33+00:00Added an answer on May 18, 2026 at 9:55 am

    Functions and Classes in C++ must be declared before their use, this is simply a declaration saying that these functions can be used from this file. These declarations are imported using header files (.hpp/.h files).

    To declare a function, you would write this:

    return type function name ( arguments );

    So this function:

    int factorial (int x)
    {
      if (x == 0)
        return 1;
      return x * factorial (x - 1);
    }
    

    Would be predeclared like this:

    int factorial (int x);
    

    Declaring classes is like this:

    class class name { function and variable declarations };

    So class Foo with method bar, and public member variable baz would look like this:


    foo.hpp:

    #ifndef FOO_HPP_
    #define FOO_HPP_
    
    class Foo
    {
    public:
      int baz;
    
      void bar ();
    };
    
    #endif
    

    foo.cpp:

    #include "foo.hpp"
    #include <iostream>
    
    void Foo::bar ()
    {
      std::cout << baz << std::endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.