Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Hey Albinopapa
 Post Posted: June 4th, 2015, 6:12 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2853
Location: Oklahoma, United States
chili wrote:
It amuses me to act like a jackass while recording, and therefore that is how I will continue to roll. I will however try to avoid sounding like a Tourettes case off his meds (when possible).


This caught my attention while reading your planetchili.net blog intro...hilarious.

Any ideas about a Wiki? Is it still going to be a thing?

If traffic picks up around here again I'd like to make it a thing. Right now I don't think the community is quite active enough to sustain one, unfortunately.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: Hey Albinopapa
 Post Posted: June 6th, 2015, 7:24 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2853
Location: Oklahoma, United States
Ok, I hate const, it's a pain in the ass. Say you have a const object and you want to use one of it's methods to access a members. Normally, you can do this, but if the object is a const reference of another object and you want to access a method of that const ref, you have to copy it into an object before you can.

Example:
Code:
class Bounds
{
 public:
       // const int Left() doesn't work either
        int Left()
        {
                return left;
        }

private:
        int left;
};
class Object
{
public:
        const Bounds& GetBounds()  // can't const the function, because I'm calling a non const function
        {
                 bounds.Update(Position, size);
                 return bounds;
        }
};


There is a snippet of the classes I have. Now if I want to call Left() from outside the Object class, in the Game class for instance

Code:
int left = obj.GetBounds().Left()


it tells me that the "object has type qualifiers that are not compatible with the member function. I can't make the Bounds object const because the boundaries will change as the object moves. Even making the returned value of Left() const doesn't work.

Using const may make sense most of the time, but sometimes, it's just a pain in the ass to work with.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: Hey Albinopapa
 Post Posted: June 7th, 2015, 2:58 am 
User avatar

Joined: May 23rd, 2013, 3:52 pm
Posts: 1236
Location: USA
lol, the only way to fix would be to make the Left() function const, as in
Code:
        int Left() const
        {
                return left;
        }

that's the point of the const keyword after the member function pretty much
const after member function declaration just means it won't change the const object's data

_________________
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
irc://irc.freenode.net/#pchili alt -- join up if ever want real-time help or to just chat :mrgreen: --


Top 
 Profile  
Reply with quote  
 Post subject: Re: Hey Albinopapa
 Post Posted: June 7th, 2015, 4:10 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2853
Location: Oklahoma, United States
Can't believe that f*ing worked. The function takes no params, so not sure why the function has to be const, should just be worried about the returned value. Anyway, thanks, completely forgot to even try it since it didn't make sense, since I wasn't passing anything in.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: Hey Albinopapa
 Post Posted: June 7th, 2015, 10:16 pm 
User avatar

Joined: May 23rd, 2013, 3:52 pm
Posts: 1236
Location: USA
heh yea, pretty much const before the function means return value is const, after the function (only for member functions) means object won't be modified, and you know what it means everywhere else lol
(thought you knew all this lol xD)

_________________
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
irc://irc.freenode.net/#pchili alt -- join up if ever want real-time help or to just chat :mrgreen: --


Top 
 Profile  
Reply with quote  
 Post subject: Re: Hey Albinopapa
 Post Posted: June 8th, 2015, 1:08 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3493
Location: Japan
albinopapa wrote:
The function takes no params, so not sure why the function has to be const, should just be worried about the returned value.


The const at the end the method signature means that the method will not alter the state of the object it is called on. Therefore, for const objects, only methods marked with const (i.e. non-mutating methods) are accessible.

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post subject: Re: Hey Albinopapa
 Post Posted: June 8th, 2015, 6:17 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2853
Location: Oklahoma, United States
Was under the impression, const at the end just meant the function wouldn't change a member value or params being passed in. Thanks for the corrections. Now I'm just having some design issues hehe. Will work a little more and see if I can't straighten them out, if not, I'll be back with a project.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: Hey Albinopapa
 Post Posted: October 7th, 2017, 11:48 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2853
Location: Oklahoma, United States
Hmm, I've come quite far with understanding const and now I don't even think about not using it everywhere I can. I've become as obsessed with it as chili...well I don't get rock hard so maybe not.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: Hey Albinopapa
 Post Posted: October 8th, 2017, 12:00 am 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 497
Location: Idiot from northern Europe
Is Chili now fully over texas holdem? Because that makes 1.5 of us

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post subject: Re: Hey Albinopapa
 Post Posted: October 8th, 2017, 4:50 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2853
Location: Oklahoma, United States
Well, this was two years ago, so maybe.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: