Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Bregma

Member Since 09 Dec 2005
Offline Last Active Apr 28 2015 06:24 AM

#5225805 What is this stuff called in c++

Posted by Bregma on 27 April 2015 - 04:44 AM

SplashViewCreator().create(); <-- What is code like this called in c++?

where SplashViewCreator is a class.

I have never seen a class initiated and used without an object of it first being created... e.g. I would expect

SplashViewCreator mySplashViewObject;

mySplashViewObject.create();


Are those two things equivalent?

No.

The equivalent code is this.

{
    SplashViewCreator mySplashViewObject;
    mySplashViewObject.create();
}

Note the scope braces. The SplashViewCreator object is created, its create() member function called, then goes out of scope immediately.




#5223379 PerfectMMORPG

Posted by Bregma on 15 April 2015 - 04:51 AM


I, of course, designed (sortof) an even better SortofPerfectMMORPG where you can DESIGN THE GAME YOU WANT !!!!

Wait, that may not be a bad idea... picture it, online players taking on the class of designers, developers, artists, or producers in a highly-competitive online roleplaying game development universe, battling trolls and backers to defeat evil and rise to the top of the marketplace.  You can be a crafter or a warrior, and PvP is not uncommon.  Various guild factions can wage releases of unprecedented scale.

 

Hmmmm....




#5223136 Advice On C++ Class Design & Implementation

Posted by Bregma on 14 April 2015 - 06:59 AM

I am doing a beginner C++ project and its simply a Library Mangement System where a student will hire, give back a book, book and hire records are stored in a binary file etc.
...
LibraryBook features I want to implement:

- The class has the expected private properties of title, author, availability, id. I have made the LMS a friend class so that it and only it can change the books availability, maybe even author, title (for scalability/extendability). Would you use friend here or maybe another technique?

Remember, a book is not a hire record.  I see no reason to use friends at all here.
 
A Student asks the LMS for a Book.  Internally, the LMS has a list of HireRecords which join the Students with the Books (with a date attribute).  It knows a Student can not hire a Book if there is a currently valid HireRecord for that Book, and since a student can only hire 2 books at a time, will also refuse the Student's request if there is more than two currently valid HireRecords for the Student (I made that last up to illustrate the flexibility of the system, and because I remember that from when I was a child).  If you save the HireRecords you can generate reports such as who has overdue books, or which Student hired which Book when for the Authorities during their Ongoing Investigation.
 
So, no, no friend required.  Just classes based on data reduced to third normal form.




#5222053 Detecting if 2 Iterators point to the same thing?

Posted by Bregma on 08 April 2015 - 07:11 AM

In summary for the OP:

 

The result of operator==() on two iterators is true if the iterators both indicate the same element in their range, false if they indicate different elements in their range, and undefined otherwise (eg. one-past-the-end of their range, or different ranges completely).  Undefined behaviour is undefined.

 

The result of operator==() of two object instances indicates the objects compare as equivalent. If it indicates two instances are equivalent when in fact they are not, you have a bug and need to fix your implementation.

 

If you find you have an inventory of 200 hats, operator==() between any specific two different hats should return false.  If the same hat is in two different inventories (for example, "things on my head" and "things I have with me", assuming the first is considerably smaller than the second but I'm not judging), you probably need to include a distinct object ID in your class and have it a part of the algorithm calculating the result of operator==() on your hats.




#5221817 are non sql databases better than sql databases?

Posted by Bregma on 07 April 2015 - 06:28 AM

No-SQL databases are better because they are web-scale.




#5221717 Using named POSIX mutexes?

Posted by Bregma on 06 April 2015 - 04:56 PM

POSIX mutexes are not an IPC mechanism and are not shared between processes.  They are not related to WIN32 mutexes.




#5219676 Global Consts

Posted by Bregma on 27 March 2015 - 12:22 PM

This discussion of whether the value of a constant is better to use than its meaning for clearest expression in code does not take in to account that 80% of the lifetime of a piece of code spent in maintenance mode.

 

Sure, you can show everyone how you're a Clever Dick because you know at this very moment that the context of a few characters out of millions of lines of code implies that a particular use of the value "4" implies it is the number of vertexes in a quad when rendering a particular set of vertexes using OpenGL, or the number of vertexes in a triangle fan pair in the GL|ES codepath.  Later, the poor desperate engineer (maybe even you) who comes along to analyze why the clipping on a face is off and the boss is screaming in the office next door because ship dates are getting delayed, well, she'll just think you're a dick.

 

You're writing literate code for people to read and understand with minimal context.  You're not writing for a compiler to understand, and you're not writing to show everyone how big your ego is (they already know, trust me).  Those requirements, rarely met by most coders I've ever met, mean you should try to convey meaning (as in, use a named constant like vertexes_per_quad) rather than value (as in, 4).




#5217325 C++ do while error

Posted by Bregma on 18 March 2015 - 06:11 AM

You have an executable statement at namespace level.  That's just not a thing in C++.




#5216424 Question About Port assignments

Posted by Bregma on 14 March 2015 - 06:35 AM

I guess if you're using UDP there might be a slight advantage to doing multiple server ports like this, but with all the complex code and hassle involved in port forwarding and the security implications involved in opening up all your ports on your firewall, it doesn't sound worth it over having a single port that hands off an accepted TCP connection to the room.  On Linux you can even pass open socket file descriptors to separate processes over IPC if you've partitioned your server that way (dunno what platform your server is running on).




#5216245 non-uniform random numbers (triangle distribution and more)

Posted by Bregma on 13 March 2015 - 04:50 AM

Just an aside: the C++ standard library has about a dozen non-uniform random number distributions, both continuous (well, real-valued) and discrete. A good place to go to for ideas because it has all the widely-used basics (Gaussian, Bernoulli, gamma, etc).


#5216026 Template not linking?

Posted by Bregma on 12 March 2015 - 04:50 AM

Where is this mysterious s_Instance defined?




#5215402 GUI Challenge

Posted by Bregma on 09 March 2015 - 06:22 AM


The only time you may run the project is once you believe it is done

This reveals you are not a developer, because a developer knows no program or asset is ever really truly done.  If you're not a developer, you're from sales so you're gonna get downvoted to oblivion.




#5214931 makefile

Posted by Bregma on 06 March 2015 - 05:50 AM

You only need to force the toolchain to build for an x86_64 target if you're not on an x86_64 host (ie. you're cross building).  It's probably much simpler to just remove the -march flag from the compiler command than to keep adding more cross-building flags to other parts of the toolchain in order to get a native build.

 

I imagine the -march=i686 was added to the original Makefile to prevent builds for Pentium II or earlier CPUs which did not support certain faster instructions.  The x86_64 architecture does not need to be restricted to processors available only in the last decades since all of them quallfy in that respect.




#5212583 How were you learning programming at the age of 5?

Posted by Bregma on 23 February 2015 - 06:29 PM


Were you hacking calculators at that age?

Electronic calculators hadn't even been invented when I was that age.  I do have memories, however, of using a slide rule at age 5 to help my mother (a science teacher) calculate grades for her class.  There's something about manipulating things given a particular input and having the output just appear that is just like programming.  Just like it.  So when my mother brought home a CARDIAC a couple year later it was easy to make the leap.

 

My kids at age 5 could barely use a mouse to make Reader Rabbit identify patterens.  Now of course they can text and google and download illegal content like any other young adults or teens, and my younger daughter can frag evil guys and zombies with the best of them, but nobody in my house has ever show any desire to make electrons dance.  Hashtag sadface.




#5210453 Operator Overloading C++

Posted by Bregma on 13 February 2015 - 05:50 AM

Firing back...

//Operator+ (refactored to trip up JPs)

MyObject operator+(MyObject lhs, MyObject const& rhs) {
    return lhs += rhs;
}





PARTNERS