• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

About C++

Status
Not open for further replies.
Level 29
Joined
Mar 10, 2009
Messages
5,016
Thanks guys, it cleared a lot of questions that I have in mind...

You can make all variables private and accesable by getters/setters only, but some people dont like that, or you can make everything public
I think people will try to protect the variables by not changing them directly from any functions, except the getter/setter...

In most cases you will define the class interface in a header file
I think classes should be defined/declared in the header since if Im not mistaken, there is no way to access it without including it to at least 1 cpp file...
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
I think people will try to protect the variables by not changing them directly from any functions, except the getter/setter...
Yes, the main reason people do it is it allows you to more precisely control function input and output for more predictable behaviour. All external interfaces should have very well defined input and output behaviour.

I think classes should be defined/declared in the header since if Im not mistaken, there is no way to access it without including it to at least 1 cpp file...
You should only define the interface in the header. The actual method implementations should go it a cpp file. This is because the header is imported into every cpp file that uses the interface it defines but you only want the class to be compiled once and then linked into the program when required.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
The key thing to note is that you define how memory is broken up with a struct while the compiler does with a class. If you define struct with 3 members then you will have exactly those 3 members converted to memory (with maybe some padding for word alignment). If you define a class with 3 members, the compiler may make 3 or more pieces of data to represent the class in memory. Some of this extra data includes class information, inheritance information, method pointers etc (generally stuff needed to support OOP).
The keyword "private" purely hides the variable from a programming point of view to reduce coupling. It is not a way to protect your code by keeping it secret.


I think the OOP information is only generated when the class is truly used in OOP(so if you dont make any methods virtual or dont inherit that class, it will not generate extra useless data)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
I think the OOP information is only generated when the class is truly used in OOP(so if you dont make any methods virtual or dont inherit that class, it will not generate extra useless data)
That is correct. However the thing to note is that it still can have extra values stored that you can never access directly and never know when they will be generated at compile time.

Changing the order of members of a struct can count as an optimization. Changing the order of members of a class generally will do little to improve performance.
 
Level 15
Joined
Oct 18, 2008
Messages
1,588
That is correct. However the thing to note is that it still can have extra values stored that you can never access directly and never know when they will be generated at compile time.

Changing the order of members of a struct can count as an optimization. Changing the order of members of a class generally will do little to improve performance.

Or, you can start writing your own compiler :ogre_haosis:

The keyword "private" purely hides the variable from a programming point of view to reduce coupling. It is not a way to protect your code by keeping it secret.

This. If you want to protect your code, scramble all variable names before releasing your compiled code to make decompilation harder, and add some protection program (Punkbuster, Fireguard, Hackshield, UCP Anti-Cheat, etc.) if you want to defend the memory values from being messed with (injected).
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
This. If you want to protect your code, scramble all variable names before releasing your compiled code to make decompilation harder
Too bad C++ does not compile with variable names unless you specifically tell it to. Welcome to direct linking where nothing but pure data values are passed.

if you want to defend the memory values from being messed with (injected).
You can try but you will never truly succeed. Nothing stops a person freezing the entire process and manipulating the threads to do his bidding.
 
Level 15
Joined
Oct 18, 2008
Messages
1,588
Too bad C++ does not compile with variable names unless you specifically tell it to. Welcome to direct linking where nothing but pure data values are passed.

Hmm true, for some reason my compiler defaults to compiling variable names.

You can try but you will never truly succeed. Nothing stops a person freezing the entire process and manipulating the threads to do his bidding.

There are always methods to protect and methods to breach those protections. I'm not to say there is any way of defence that can not be breached in a non-sandbox environment, but at least you can lower the number of offenders. If you make something worthy of hacking/cracking, sooner or later you will find those full-time hackers around.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Hacking with system DLLs is unstoppable.
I hold in awe the genius that injected code into a DirectX DLL that you simply put in some specific game's directory.
The operating system itself then handles the injection into game code, since it will always load that DLL.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
You can detect things like aim bots using statistics. It is unlikely that a human would be landing so many shots under certain condition (and if they could, then an aim bot would hardly give an unfair advantage). And if the aim bot is rigged to trick the statistical analysis then it is only half as cheating and much less a problem.
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
I really dont care about that atm, Im just asking coz how can they extract the build already?...

anyway, let's get to the topic of this thread, I've learned that c++ can use scientific notations;
JASS:
   cout << 1e3 << endl; 
   cout << 1e+3 << endl;
   cout << 1e+00000000000000000003 << endl;
   cout << 1e+03 << endl;
all outputs 1000 but which is recommended to use?

Also;
float = 7 digits
double = 15 digits
long = 19 digits

but why this cant displays correctly?
JASS:
   float x = 1234567;
   double y = 1234567;
   long z = 1234567890123456789; //displays corectly

output;
1.23457e+06
1.23457e+06
1234567890123456789
 
Level 6
Joined
Aug 26, 2009
Messages
192
I really dont care about that atm, Im just asking coz how can they extract the build already?...

anyway, let's get to the topic of this thread, I've learned that c++ can use scientific notations;
JASS:
   cout << 1e3 << endl; 
   cout << 1e+3 << endl;
   cout << 1e+00000000000000000003 << endl;
   cout << 1e+03 << endl;
all outputs 1000 but which is recommended to use?

Well, obviously the one which is most easy to read. In this case, either 1000 or 1e03. But attention! 1000 != 1e03. 1e03 is actually a double and 1000 is an integer, you might have to cast it to int/long since there might be information loss.

but why this cant displays correctly?
JASS:
   float x = 1234567;
   double y = 1234567;
   long z = 1234567890123456789; //displays corectly

output;
1.23457e+06
1.23457e+06
1234567890123456789

Actually they all display correctly? e+06 = *10^6 and hence:
1.234567 * 10^6 = 1234567.
It's just using the scientific form.
And well, long is written like this, since a long can't have the representation 1.234567890123456789e+18.
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
Actually they all display correctly? e+06 = *10^6 and hence:
what I mean was NOT in scientific notation...

printf lets you specify how the numbers are displayed.
I think prinf is a C keyword...

Standard IO streams are good at that too.
I just used setprecision for that, works fine but still havent got a clue how to display it without that...
 
Status
Not open for further replies.
Top