I have written my first library. Feedback is very velcomed!

I have just finished reading a C++ book. This is my first library, probably not very useful, but it was a learning experience. I would appreciate some feedback on the code. Like if ive misunderstodd or used something wrong.

You can use git to get the files from github, and then make the binary with with makefile, or just browse the source on github:

https://github.com/dvikan/AsciiCards/wiki
What is this meant for?

Also, check out this header file I recently released. It makes creating and modifying linked lists easier.

https://github.com/packetpirate/Linked-List-Header
Last edited on
Its a class for representing the 52 different standard playing cards. Can be used in game which involve cards. E.g. implement some poker logic.
closed account (S6k9GNh0)
1
2
3
4
5
6
std::string getSuit();

/**
* Returns "black" or "red".
*/
std::string getColor();


For things like this, it would be easier and more optimized to use an enum type.
Also, for realistic criticism, the library isn't flexible enough for shared use. Although you may not care ;P.
closed account (3hM2Nwbp)
A few things that stood out to me:

1) Your class CardException - is there a reason you're not deriving it from std::exception?
2) CardException doesn't use anything in <iostream>, so you might consider removing the include.
3) You might consider passing const string references in your CardException class to avoid making unnecessary copies of strings.
4) CardDeck and Card have virtual destructors - was this intentional?
5) A few other places, you're passing vectors by value, where it could be by reference.
6) computerquip already hit the enums

All in all, it's not bad. What I've listed are pretty much all minor points.
Last edited on
closed account (S6k9GNh0)
If I'm not mistaken, a LOT of tutorials and books that I've read actually make it a rule of thumb to make all destructors virtual.
In my experience, it's generally a good idea if you're dealing with Polymorphism and Virtual Inheritance:
http://www.cplusplus.com/forum/general/44633/
Last edited on
If I'm not mistaken, a LOT of tutorials and books that I've read actually make it a rule of thumb to make all destructors virtual.


I don't think that is very sound advice. Remember that as soon as you add a virtual method or virtual destructor to a class, the class automatically gets a vtable pointer that it wouldn't otherwise get. This memory consumption is a penalty to any programmer who never intends to derive from the class, and was largely the thinking behind not making any STL containers have virtual destructors.

[In general, the C++ committee's overriding mantra is to not make programmers pay for things they don't use.]

Thanks for replies!

Will take them into consideration.
Topic archived. No new replies allowed.