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

The Archive Base Latest Questions

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

in a book i am reading to learn basic c++, there is this example:

  • 0

in a book i am reading to learn basic c++, there is this example:

#include <iostream>
using namespace std;

class Point {
private:             // Data members (private)
int x, y;
public:              // Member functions
void set(int new_x, int new_y);
int get_x();
int get_y();
};

void Point::set(int new_x, int new_y) {
x = new_x;
y = new_y;
}

int Point::get_x() {
return x;
}
int Point::get_y() {
return y;
}

My question is, is it not possible in c++ to include the definition of the member functions inside the class itself? The above seems quite messy. The book says to define a class member function you should use ‘return_type class_name::function(){arguments}. But in C# you can just do it within the same class and it is less code. I haven’t been able to find much about properties in c++. Thanks for help.

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

    Although it is possible, it’s not really recommended. Actually, the way it’s done in your book isn’t how it should be done either (and hopefully, later on in the book that will change!). The way you’ll see it done 99% of the time (yes, I pulled that number out of my ass) is a class definition in a header file (.h extension) and the definitions in a source file (.cpp extension). The header file will be imported so to speak, into the source file via #include.

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

Sidebar

Related Questions

I'm reading the book LINQ Pocket Reference and there is a particular example (slightly
I'm currently reading a book about ASP.NET MVC3 to learn working with this framework.
While reading a book about JavaScript I stumbled across an example: var names =
I'm reading this book on C# and .NET and I'm learning a bunch of
I've been reading the book Learn Objective C on the Mac, and I was
So, I'm reading this book: C++ GUI Programming with Qt 4, Second Edition by
I'm reading a book called Java and C: Key Differences, Learn Objective-C for Java
I've been reading things here and there for a while now about using an
I'm reading Chris Pine's book Learn to Progam (it's about Ruby). Right now I'm
I am reading a book about ruby, it learn me that I write my

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.