Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › C++/C Programming › Classes in C++

Classes in C++

Posts 1–4 of 4 · Page 1 of 1
ZE
zeco
Classes in C++
Well this is more of a question on Programming style ,I think....

In every example Of OO (with classes and what not) Programming I see with C++, i've noticed a trend. The class functions(methods?) were always written outside of the class definition. I don't know why but this irks me to no end. Is there anything in particular that is wrong with writing all of the class methods within the class itself? This just makes more sense to me and annoys me less.

It's the one thing, visually, that i like better about Java than C++


For example:
Why is it like this:
Code:
class CRectangle {
    int x, y;
  public:
    void set_values (int,int);
    int area ();
};

void CRectangle::set_values (int a, int b) {
    x = a;
    y = b;
}

int CRectangle::area(){    
    return (x*y);
}

int main () {
  CRectangle rect, rectb;
  rect.set_values (3,4);
  rectb.set_values (5,6);
  return 0;
}
Instead of this:
Code:
class CRectangle {
    int x, y;
  public:
    void set_values (int,int){
        x = a;
        y = b;
    }

    int area (){
        return (x*y);
    }
};


int main () {
  CRectangle rect, rectb;
  rect.set_values (3,4);
  rectb.set_values (5,6);
  return 0;
}
The former(first one) Just seems to create more clutter.
Basically i'm asking, are there any specific reasons it is done this way?
If there are, are the reasons coding style, organization of some sort, or some practical reason that i haven't noticed.

This question applies to the constructor/deconstructors as well as the methods

Thanks for your answers. If i get any.
#1 · edited 17y ago · 17y ago
SG
sgtmattbaker
I'm guessing you don't know what inline functions are but basically when you compile your program a normal function call will look like
push para3
push para2
push para1
call function
this function would look like function(x, x, x)

now if this was inline instead of calling the function the compiler will put the function body(everything from the first { to the last }) in place of the call.

So now when you write a function like that in a class its an inline function. With functions that simple it can be more efficient than making the compiler call it. If you have a big function your performance will drop and if you call that function a lot you will get a way bigger program size.
#2 · 17y ago
ZE
zeco
Quote Originally Posted by sgtmattbaker View Post
I'm guessing you don't know what inline functions are but basically when you compile your program a normal function call will look like
push para3
push para2
push para1
call function
this function would look like function(x, x, x)

now if this was inline instead of calling the function the compiler will put the function body(everything from the first { to the last }) in place of the call.

So now when you write a function like that in a class its an inline function. With functions that simple it can be more efficient than making the compiler call it. If you have a big function your performance will drop and if you call that function a lot you will get a way bigger program size.
Thanks a lot, that makes perfect sense =). Is there anyway to define the function in the class without it being an inline function? And is it frowned upon to do that too much if it is possible?

P.S. I did know what inline functions are, but thanks for explaining it anyway =)
#3 · 17y ago
why06
why06
hey beats me. Haven't got into classes yet in C++.
#4 · 17y ago
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Similar Threads

  • [Tutorial]Change class without respawnBy vir2000 in Game Hacking Tutorials
    0Last post 20y ago
  • Guild Wars New ClassesBy Chronologix in General Gaming
    24Last post 20y ago
  • Heavy Weapons Class mine bug. I had no idea.By NukeAssault in General Gaming
    2Last post 20y ago
  • what it's like to have religion classBy ace76543 in Spammers Corner
    7Last post 19y ago
  • This is what math class does to youBy apitite.for.distruction in Art & Graphic Design
    14Last post 19y ago

Tags for this Thread

#bobo#c++#classes#objects#oop