jonathanjansson

Members
  • Content count

    55
  • Joined

  • Last visited

Community Reputation

271 Neutral

About jonathanjansson

  • Rank
    Member

Personal Information

  1. Hiding multiple schemes within URI

    There are no skipped characters after ':'. The variations cover the following cases:   scheme://authority/absolute/path scheme://authority scheme:/absolute/path scheme:rootless/path scheme:   http://en.wikipedia.org/wiki/URI_schemes lists some examples how various applications implement their URI schemes. Some of them abuses the authority component as a first path segment which seems wrong. It is allowed to skip '//' and start the path immediately after ':'.
  2. std::vector vs std::unique_ptr

    [Edit] I didn't read the other replies careful enough and managed to repeat a lot of information except how to change the deleter! [Edit] Actually I removed my answer completely because it is wrong to change the deleter. std::unique_ptr<int[]> selects the corret deleter already. Listen to Edd!
  3. How to cross-platform ?

    You only need to share the code on the different platforms. What IDE and build system to use can be different. It is a little extra job to maintain the build scripts but not much.
  4. C++ Logging Class

    [quote name='ObsessedMikey' timestamp='1309366871' post='4829144']This does work, but how would you go about implementing std::endl or something equivalent?[/quote] I never bothered to find out until now :-) They are called stream manipulators and it's my guess that if you pass the address of a function to a stream then the stream will call that function. [code]#include <iostream> std::ostream& hello(std::ostream& os) { return os << "world!"; } int main(int argc, char** argv) { std::cout << hello << std::endl; return 0; }[/code]
  5. C++ Logging Class

    [quote name='averron82' timestamp='1309360511' post='4829097']One slight difficulty is that I would ideally like to make it compatible with std::endl, and I'm unsure how this would be achieved. [/quote] This worked for me [code]template <typename T> Log& operator<<(T const& value) { m_filestream << value; return *this; }[/code]
  6. problem with templates and class constructors?

    Maybe something like this? [code]template <typename T> CModel* CreateInstanceCModel() { CModel* model = new T(); m_modelList.push_back(model); return model; } template <typename T, typename A1> CModel* CreateInstanceCModel(A1 const& a1) { CModel* model = new T(a1); m_modelList.push_back(model); return model; } template <typename T, typename A1, typename A2> CModel* CreateInstanceCModel(A1 const& a1, A2 const& a2) { CModel* model = new T(a1, a2); m_modelList.push_back(model); return model; } // Etc... [/code] and then [code]CModel* model = CreateInstanceCModel<SpecificModel>(arguments);[/code]
  7. Help understanding objects? (C++)

    [quote name='ebontide' timestamp='1306269711' post='4815299'] [quote]"sword", "shield" and "armor" as they appear in the code are string literals[/quote] I was with you that far, but pretty much everything after that went miles over my head. I'm getting the feeling I'm in no position to start worrying over objects by the responses I'm getting. I'll keep to my studies and come back better equipped to tackle this hopefully. Edit: Actually, I can make bits and pieces of sense from what you're saying, but its so clouded with misunderstanding on my part that its hard to tell just what to make of it. Again, I think its just a lack of understanding of base concepts and I need to study more. [/quote] Maybe don't worry so much and just continue with the book and play with examples. It takes time to really understand programming. :-)
  8. I'm failing college because I have dysgraphia. What should I do?

    [quote name='SteveDeFacto' timestamp='1306266975' post='4815271'] Currently I'm having the hardest time in my psychology class because the teacher expects us to write full essays in less than 15 minutes and I can't take down notes fast enough before he flips to the next slide. I know I'm going to fail but I don't know what to do? [/quote] Bring a camera to class or if he shows slides on the computer you can ask him for a copy. Often the material can be found on the course's website.
  9. Help understanding objects? (C++)

    "sword", "shield" and "armor" as they appear in the code are string literals which works just as in C. Because the inventory is a a vector of string the push_back function will automatically take a string object as the parameter. But when you pass string literals the C++ compiler will try to create an anonymous string object by pasing the string literal to the string constructor and then pass that string object to push_back. The string objects are not said to be members of the vector class. Class members are only the declarations of variables and functions what you can see in the class declaration. When you want to talk about the data that was put into a collection object it is better to use the word elements or objects.
  10. Sometimes I do it to explore some problem but I always want to understand why it worked. If I am debugging something I might try to swap two lines of code. If that worked I would not submit the fix without some further investigation. Maybe the library should be used in a different way than we thought or perhaps I can improve the implementation of the library if it is not third party code. I have worked with people that just randomly fiddle with the code until it works. I remember one occurance where a "fix" made the bug seem to disappear so I guess the bug could be closed. But that fix made pretty much everything else break. If you can't explain why it worked you should not submit the code! Fix the underlying bug if possible.
  11. C++ coding standard

    I like to compare naming conventions so wrote a review of two good ones below... I only consider naming here, not any other conventions. I have tried the naming conventions from [url="http://hobbit-hole.org/cpp_coding_guidelines.html"]C++ Coding Guidelines by David Abrahams and Nathan Myers[/url] (an old document which pretty much is the Boost naming conventions) and [url="http://msdn.microsoft.com/en-us/library/ms229002.aspx"].NET Guidelines for Names[/url]. Both conventions has chosen to name pretty much everything in the same way. [b]Boost[/b] Boost names identifiers using lower_case_and_underscores except for template parameters which are PascalCase. I believe the reason is to follow the C++ Standard Library conventions but also because in C++ the distinction between different kinds of identifiers can be blurry. For example std::sort can take either a function or an object as the comparator or an enum value can be used as a result variable in template meta programming. Following the Boost style makes the code blend in with the standard libararies and Boost very nicely but I found that i got a lot of name collisions between types and variables. One can argue that you should come up with better names such as "player* shooter" but sometimes it seems impossible so I ended up typing "player* plr" and stuff. In the long run it was too much so I started using Pascal_Case_With_Underscores for type names and this worked fine. After a while I got tired of this style and somehow the code doesn't look very firendly so now I try the .NET naming conventions instead. [b].NET[/b] .NET uses PascalCase for all visible identifiers and I think the point is to get naming collisions so it is easier to write code that is compatible with case insensitive languages. The nice thing here is that it only applies to names that are in any way public (or protected). Function parameters are named with camelCase and it is common to use camelCase for local variables and private data members too. Private variables are often prefixed with _. This gets rid of most of of the name collisions I had using the Boost style. When I do get a collision it is because a struct has a public member that is named the same as it's type but you just have to come up with better names in those cases. Instead you can name variables the same as functions such as "Player* nearestPlayer = NearestPlayer()" or "Vector length = Length(vector)". So far I like the .NET conventions. I think that PascalCase and camelCase styles are more common. [b]Edit[/b] I have found that name collisions with C++ standard naming conventions is not a big problem. To declare a member variable with the same name as a type you just need to repeat the namespace before the type and it will work. Local variables with the same name as a type works without any tricks most of the time. Even when a type name is hidden by a variable name operator:: can be used to access static members of a class without repeating the namespace.
  12. When to return by reference?

    Returning by reference is how [i]operator[][/i] is implemented on containers.
  13. How many of you use C for game programming?

    [quote name='francoispress' timestamp='1295843589' post='4763738'] I'm very curious. I use it myself because of its simplicity and less haggling with accessor functions, member access, etc. Though many may not agree with me. I'm just curious about what people's take on this is. [/quote] I have this crazy idea sometimes that I want to program in C so at one point I rewrote my latest project to C. I may go back at some point but I am thinking that if I need a high level language I would embed Lua instead of using C++. I was thinking about what you say about accessor functions. You don't have to use them in C++ and you can, and sometimes should, have them when programming C. But it was quite a relief to get away from idiomatic C++ and just solve the problem. But this limitation is just our heads. I also think C is quite fun. It is nice to find different solutions to the problems. But having to write container classes is a mess. It takes a few iterations to get them right. I know I am talking against my last paragraph where say "just solve the problem" because I would get some stuff done faster if I would stick to C++ and code with an open mind. Also C code compiles a lot faster than C++. I think 2 or 3 times faster!
  14. IDE without WORKSPACES/SOLUTIONS

    I found that KDevelop integrates nicely with CMake and can do code browsing and auto completion. It actually has the best understanding of C++ that I have ever seen in an IDE. I think it looks at the Makefile to find include paths and stuff. Still it creates one little text file with 4 lines of configuration and I still need to write the make files. So it is not easier. It is work that needs to be done.
  15. Can someone help me name my API?

    Names are hard! I sometimes take a dictionary and try find words that are cool or funny and try to combine them. Like... Beleive 3D Coral Engine Sai (A weapon, but maybe it means "Scene, Audio and Impulse")