2,898 Posted Topics
Re: Moving from Java to C++, the main thing to understand well is the distinction between Java's reference-semantics and [C++'s value-semantics](http://akrzemi1.wordpress.com/2012/02/03/value-semantics/). Simply put, everything in Java is a reference (or placeholder, or pointer) for an object (managed by the garbage collector). In C++, everything is a value (or object, or variable) … | |
Re: GCC works for many many architectures, certainly including most mobile phone or smart phone architectures (mostly ARM and x86). A friend of mine compiled Ubuntu (Linux) from source for his Nokia mobile phone (not a smart phone) (and was later able to compile robot control software (C++), allowing him to … | |
Re: I think I can provide a bit more explanation. A pointer (e.g., `hello`) is just an ordinary variable (like an integer) that stores the address of an object. That value (the address) can be changed, like any other variable value, unless it is const. Here are a few cases: Hello* … | |
Re: > Would anyone date these 3 girls kat von d or Levy Tran or Sarah Miller? Definitely yes. Ink is sexy (at least, those that compliment the curves). But I think dating those 3 girls at the same time would be a bit too much to handle ;) | |
Re: Here is the first statement explained: [cast to non-const int pointer] ( [get a pointer to 'i' (const)] ); const_cast<int*> ( &i ); Here is the second statement explained: [cast to non-const int pointer] ( [get value of 'i'] ); const_cast<int*> ( i ); The error is because an integer … | |
Re: Let me demonstrate why all your trivial examples and tests are flawed due to their simplicity. I created the following C example code: int just_if(int value) { int result = 0; if(value == 1) result = 2; if(value == 2) result = 4; return result * result; }; int else_if(int … | |
Re: Besides the inherent simplicity of the switch-case compared to else-if, there is also some performance benefit to a switch-case, at least, nominally (i.e., if the compiler is not smart enough to produce the most efficient code in either case). In the classic use of a switch-case, something like this: enum … | |
Re: RLE: Run-length Encoding. Generally, such encoders can be programmed as an on-the-fly mapping between input (uncompressed image pixels) and output (compressed image pixels). In this case, the encoding is best described in terms of a state machine. There are two states possible when writing pixels: 1. Writing a sequence of … | |
Re: Why don't you just post it here? I don't mind having an open discussion on your "changes" here. For the benefit of all, that is the spirit of a forum. | |
Re: > Is there any problem if some shared data is accessed by multiple cores on a CPU? Yes. There are several issues possible. Technically, if all you do, in all the threads, is to read the data, then there won't be any issues. Where things get ugly is if one … | |
Re: There are too many to list them all, especially without a more definite idea of what you are actually looking for. The [Boost libraries](http://www.boost.org/) are probably a good first stop. For the rest, you'll have to tell us what features or particular application domain you are looking at (and RogueWave … | |
Re: > So... do you think should I continue to learn c++ on linux ? Or stick to windows ? I'll be writing portable code anyways. Definitely, yes. Linux is by far preferred to Windows as a development OS. Windows is more of an impedance to development than anything else. It … | |
Re: @deceptikon: "I'd call such a system "stupid"." Don't be so quick to judge, these design principles are in contradiction to the "server-client" paradigm, but they are not "stupid", in fact, they are the basis for most decentralized systems, with some notable examples like Git, Mercurial, ROS, and the Internet! > … | |
Re: telnet is just one of those basic remote login methods. It is not used very much because it is not secure (not encrypted). Most remote access work is usually done using SSH (or similar secured shells). Both methods basically allow you to just login to a computer, remotely, and be … | |
Re: Some time ago, a colleague happened to ask me if I was active on any online forums. I told him I was a mod on Daniweb. He said: "Daniweb? Never heard of it." So, I popped up a browser on the Daniweb page, and he said: "Oh yeah, **the purple … ![]() | |
Re: For memory debugging purposes, you should use [Valgrind](http://valgrind.org/). If any tool can do what you are looking for, it's Valgrind. | |
Re: > It is a shame schools are teaching with 20 year old compilers. That's usually correlated with professors being 3 or 4 times older than that. And the last time they checked they were using the latest and greatest compiler. > I am learning C++ on Turbo C++ 3.0 Turbo … | |
Re: > There also it should display one linker error since we have defined static variable inside .h file. No. There is a certain allowance for static const data members which is similar to the allowance for inline functions (functions defined in the header file either within a class declaration or … | |
Re: The operations in addbook() (saving in file) and the operation in display() (loading from file) are not the inverse of each other, and thus, the loading will fail. Here is what I mean, say you have the following values for your variables: string bookname = "C++ Primer"; string publisher = … | |
Re: Well, there is a huge difference between the two. Try compiling this: Foo(true, 2, 5.0, "dude"); Meh(true, 2, 5.0, "dude"); Meh requires that all parameters have the same type (or, at least, all be convertible to the type of the first argument). That's not the case for the Foo version, … | |
Re: Just ask them how they evaluated whether the programs are working or not, such that you can use that to learn what you did wrong in that code. Don't talk / whine about how it works on your end, there's no point in that, they're probably not going to be … | |
Re: I wish I saw that this thread earlier, because I knew the issue right away when I saw "`clock()`" in your code. The `clock()` function basically returns the number of clock ticks consumed by your program (overall process). Because each core has its own ticking clock, well, if you have … | |
Re: > How to find which operating system is running the PC in C++? Well, C++ is a compiled language, meaning that a particular operating system is always targeted when compiling the code, i.e., the operating system type is known at compile-time. And all compilers will define a number of predefined … | |
Re: I generally prefer giving personalized answers, but your question indicates serious misunderstanding of basic concepts of class / object / variables / member / ... I think it would be better if you read [this tutorial on classes](http://www.cplusplus.com/doc/tutorial/classes/), which certainly answers your question better than I could. | |
Re: A waste collection vehicle scenario sounds a lot like a [travelling salesman problem](http://en.wikipedia.org/wiki/Travelling_salesman_problem) (TSP). Or at least, like other routing problems. These are usually modeled as integer problems (or Integer Linear Programs (ILP)), or combinatorial optimization. > So here raises the question why should I use GA. How do I … | |
Re: I don't mean to burst your bubble, but this kind of thing has been around for a long while, and are used quite a bit. Take, for example, the [Boost.Property-Map library](http://www.boost.org/doc/libs/1_52_0/libs/property_map/doc/property_map.html) which has generic concepts for mapping keys to properties, either in the same way as you use `std::map`, or … | |
Re: > But why does the video tutorial use iostream and works for him? Am I using an older version of C++? Maybe so, maybe not. Technically, the old C++ standard (from 2003, C++03 or C++98) does not require the `<iostream>` header to include the `<string>` header, and most compilers would … | |
Re: `NULL` is just zero for pointers. In actuality, there is no difference in the value. It is merely a convention that you should set and test pointers with NULL, and use 0 for integral type (int, short, etc.). On many compilers, NULL is just a `#define` for 0. In newer … | |
![]() | Re: You should create the thread object when you want it to start. And the `join()` function is basically to wait for the thread to finish (i.e., join the thread with the current thread). If you want the thread to start when j is equal to 25 and then finish it … ![]() |
Re: > Hollywood lost all morals years ago when they started producing R rated movies which contain lots of violence, cursing and sex. I beg to differ with granpa AD. How exactly can you address difficult moral topics without including things that are difficult to watch? Ignoring certain difficult realities is … | |
Re: I would be in favor of a feature similar to "flag bad post" but for an edit request, for small edits like fixing formatting. From what it sounds like, you are kinda asking for a system very similar to what is on stackoverflow (progressive moderator-powers as rep goes up, acceptance … | |
Re: There is a conflict between your declaration of the struct Movie in the main file and in the DvdInfo class. I would recommend that you move the struct Movie declaration out of the DvdInfo class to just above it (still in the dvdinfo.h header). And remove the declaration in main … | |
Re: The solution to your problem is to use dynamic loading of the DLL. Look at the functions: [LoadLibrary()](http://msdn.microsoft.com/en-us/library/windows/desktop/ms684175(v=vs.85).aspx), [GetProcAddress()](http://msdn.microsoft.com/en-us/library/windows/desktop/ms683212(v=vs.85).aspx), and [FreeLibrary()](http://msdn.microsoft.com/en-us/library/windows/desktop/ms683152(v=vs.85).aspx). This is basically the way that you can programmatically call a function (LoadLibrary) to load the DLL, then make calls to the GetProcAddress function to obtain function pointers to … | |
Re: Shouldn't it be `melstart[i]` and not `melstart[0]`? Also, you should use the `reserve()` function instead of resize if you are going to use `assign()` after, that will avoid the default-construction of all the objects that resize() would trigger. So, I guess this should work: mel[i].reserve(mellength[i]); mel[i].assign(temp[melstart[i]], temp[melstart[i]] + mellength[i]); Also, … | |
Re: First of all, the iostream library is already buffered under-the-hood. So, there isn't much reason for you to add another buffer on top of that (although it might help). The reason for your slow performance with this line: flowC << prevsid << ", " << threadid << endl; is in … | |
Re: The `std::set` container is a sorted container which means that it will not allow you to modify the elements that it contains, because that could break the ordering. This means that set iterators will only give you `const` references to the elements of the set, i.e., `(*it)` is a const … | |
Re: > I have a some libraries which have a lot of common classes but the namespaces are different. Most of the code I was writing could be easily reused by classes in both libraries so after some reading I tried a technique of using the templates to pass namespace. That … | |
Re: You can use the "Widget" object, and a [lay out](http://qt-project.org/doc/qt-4.8/designer-layouts.html). It's kind of hard to explain how to do this, but it is easy. Say you have a main window. You can create a Widget that you put on it. Then, create a second Widget that you put on the … | |
Re: The difference in total memory used between a vector or an array is going to be negligible (probably only one pointer and two integers). The use of a vector is going to take a bit more time to allocate the memory because it must ask the heap to allocate a … | |
Re: Quick answer: [C++ Primer, 5th Edition](http://www.amazon.com/Primer-5th-Edition-Stanley-Lippman/dp/0321714113/ref=sr_1_1?ie=UTF8&qid=1354763774&sr=8-1&keywords=c%2B%2B+primer). Long answer: [Read this on-going discussion](http://www.daniweb.com/software-development/cpp/threads/70096/c-books). | |
Re: The problem is that your Forward_Euler method takes function pointers as parameters, but "f", "gleft" and "gright" are member functions of the class C. These are not the same thing and thus, you get errors. There are a number of options to solve the problem. 1) You could make the … | |
Re: I don't know what the exact numbers are, but one thing is for sure, if you were to compile a sum of all the down-votes versus up-votes found throughout the database, you'd get an overwhelmingly positive count at the end. That speaks to the fact that we, human beings, prefer … | |
Re: > Alas, my current laptop must go in to the shop for some overdue repairs. My power supply and/or connector are failing, my keyboard is chattering and three of my USB ports are intermittent. Also, my feet have fallen off (the little rubber ones) and my display is dimming. I … | |
Re: Line 5 uses "non-static data member initializers". This is a new feature of C++ (C++11) and many compilers do not support that feature yet. I compiled your code successfully with GCC 4.7.3, and I would guess that version 4.7.0 and above will compile it fine. However, version 4.6.3 does not … | |
Re: First, you can use the standard function [`std::unique`](http://www.cplusplus.com/reference/algorithm/unique/) (from `<algorithm>` header) to remove any consecutive spaces by using this predicate (requires header `<locale>` for the `std::isspace` function): bool isConsecutiveSpace(char a, char b) { if(std::isspace(a) && a == b) return true; return false; }; // call std::unique as so: std::string my_string … | |
Re: You could just use a pointer to a data member of the class held by the upper-level list. In other words, you can use this: template <typename TopContainer, typename TopElement, typename BottomContainer> void genericFoo(const TopContainer& topList, BottomContainer TopElement::* bottomList) { for (auto it = topList.begin(); it != topList.end(); ++it) { … | |
Re: If it is a method that any kind of "ExtraTerrestre" can implement in some way (as it seems from your code), then that method should be a virtual method of the base class (ExtraTerrestre) and overridden in each derived class (Dalek and Cylon). As so: class ExtraTerrestre { public: // … | |
Re: [Cygwin](http://www.cygwin.com/) is basically what you want. It is exactly that, a unix-like terminal for Windows. It isn't perfect (but nearly so), and might give you a bit of trouble here and there, mostly if you didn't install the packages (in the manual install configurations) that you needed (and, as a … | |
Re: > But could this somehow lead to a crash? (say some illegal access of memory) Sure it can. For example, what if, in the middle of a loop that iterates, with iterators, through the elements of a vector, another thread resizes the vector, effectively changing the memory location of the … |
The End.