353 Posted Topics
Re: The boost::thread class forward declares a struct called dummy. Long story short, you can work around it by adding a definition in one of the.cpp files for your project. [code] namespace boost { struct thread::dummy {}; } [/code] For AkashL, just create a console CLR project and throw in a … | |
Re: [url]http://www.cplusplus.com/reference/string/string/replace/[/url] :) | |
Re: Fun. :) How about something brute force to get you going? [code] for (int i = 0; i < rows; ++i) { int k = i * 2, m = 0; for (int j = 0; j < cols; j += 2) { int offset = k + (rows * … | |
Re: It does not look comprehensive at all. With so many completely different topics and only 2 years, Edward cannot imagine you would become especially competent in any of them without a lot of extra self study. But if it is an accredited school, the degree you get will help in … | |
Re: > I'm not saying your style's wrong; but it's better to slim down on your lines of code. The two styles do different things. The first style only makes the specified names available. The second style makes all names in the namespace available. It is easier to get name collisions … | |
Re: > Are there any roads you can keep me from going down in this process? Unless failure means big money loss, Edward prefers to throw juniors to the wolves. The school of hard knocks is the most effective one, after all. :D Try designing and writing the program yourself once, … | |
Re: > Yet when I got rid of those new initializations it went back to running perfectly well. Given that description, Edward would guess that previously run code has corrupted the stack pointer. Bus errors usually happen when code tries to read or write to misaligned addresses. If the stack pointer … | |
Re: Your problem looks like the classic trick question: "What is the time complexity of printing a binary search tree?". It is a trick question because "everyone knows" that binary search trees are have logarithmic complexity, but to print all of the nodes in the tree, the algorithm still has to … | |
Re: As long as the file format supports that kind of formatting, sure. Edward can copy code from Visual Studio to MS Word and formatting/coloring is preserved. Whether it's a good idea or not is something you can to figure out on your own. :) | |
Re: > how i can develop my own programming language that will fullfills all the requirements of the present industry Scala already exists, and it's a beast. :D It sounds like you want to create a *real* language as opposed to a toy for learning language design and implementation. Start by … | |
Re: Edward can't help but think of malware when program requirements include words like "secretly". | |
Re: Edward would like to master the basics... Nothing is more marketable than a developer with super sturdy foundations. > So now I'm thinking "What now"? Now you start writing software. There are system APIs and GUI APIs, and tools like Boost that will keep you busy learning for a long … | |
Re: > This is surely a massive performance hit, especially if classes contain allocation and de-allocation statements? It *can* be too much overhead, but in those cases you should be storing a vector of light weight smart pointers. [code] int main() { vector<shared_ptr<Foo> > container; for (int i = 0; i … | |
Re: These samples are using Boost and totally from memory. Please excuse any lapses in Ed's ability to recall details of a complex library. :D The concepts should be accurate though, and easy to correct from the Boost documentation. > mkdir () // make a new folder [code] #include <boost/filesystem/path.hpp> #include … | |
Re: [LIST=1] [*]The file is closed in the loop. That does not work well if you want the loop to continue reading the file. ;) [*]The file reading loop does not do anything else. Only the last book in the file will be printed. [*]createBook returns a pointer to the new … | |
Re: > It there any way to telll the compiler that from this to that point, everything I implement belongs to a certain class? There is no way the compiler knows that you are implementing a member outside of a class definition unless the name is qualified. The only way to … | |
Re: > 1. What are the most recommended books on c++ algorithms? Knuth's Art of Programming books are the only ones consistently recommended, but they are not in C++. > 2. Algorithms in C++ by Robert Sedgewick - any experiences? Great book, worst code ever. Edward still recommends it because the … | |
Re: > What is the point (eheh) of a pointer to a pointer? The two most common uses are faking a 2D array with heap memory, and faking pass by reference for a pointer. The code you posted looks like the latter. The output of the function is a pointer, but … | |
Re: > Please don't say perl.... Edward can only assume you are prohibiting Perl because it is the most obvious and correct answer to your question. ;) Modern "scripting" languages with native regular expression support are going to be your best bet. Perhaps Python or Ruby? | |
Re: lobjc is the Objective-C library. You do not need it in C++, so remove it from the list of included libraries and that error should go away. Edward has not used Dev C++ in ages though. You will need to figure out where to make that change. Probably in the … | |
Re: In anticipation of the thread being split, Ed has a comment. > I suggest using a bitwise AND (much quicker as it doesn't involve a division) This is a common misconception. Every time Edward tries to confirm such claims, the result is that the two are competitive at all optimization … ![]() | |
Re: > because a char array is the same as a char * This can be a misleading statement. Arrays are not pointers, but an array name *is* converted to a pointer most of the time in practice. > every one know that scanf statement should use "&" ambers ion > … | |
Re: getline()'s first parameter is an istream reference. It looks like you want an intermediate string stream. [code] #include <fstream> #include <iostream> #include <string> #include <sstream> #include <cstdlib> // For exit() int main() { std::ifstream arquivo("entrada.txt"); if (!arquivo) { std::cout << "File not found\n\n"; std::system("PAUSE"); std::exit(EXIT_FAILURE); } else { std::cout << … | |
Re: What do you mean by "bad_ptr"? Edward doesn't have any problems with that syntax. [code] #include <iostream> #include <iomanip> int main() { const int n = 16; unsigned int **intext; intext = new unsigned int*[n]; for (int i = 0; i < n; i++) intext[i] = new unsigned int[n]; for … | |
Re: Assuming the question is about construction of an object in a class hierarchy, Edward has trouble answering questions that are answered easily by Ed's intuition. Why does it not make sense for the base parts of an object to be constructed before the derived parts? | |
Re: It's easy to write slow applications with WinForms, but there are [URL="http://msdn.microsoft.com/en-us/magazine/cc163630.aspx"]general applicable tips[/URL] for keeping things snappy. Anything more specific depends on how your forms are set up and what they do. | |
Re: > Is the initialisation code added automatically ??? Yes. :) | |
Re: > i want to know , how to optimize bubble sort Switch to a faster algorithm. :D Bubble sort is one of the least efficient sorting algorithms, to the point that trying to optimize it is wasted effort when even switching to another quadratic performance algorithm like insertion sort would … | |
...does not work in Firefox 3.6.3. The page is scrolled to the top and the code box remains in highlighted mode. | |
Re: How do you know it's obsolete if you don't know whether something newer exists? Obsolete means there is a newer method, not that the article describing the current method is old. ;) If you just want a recently updated article, the [URL="http://java.sun.com/docs/books/tutorial/2d/printing/index.html"]Java Tutorial[/URL] is a good start. | |
Re: > is the absence of a definition of the vector element the reason why you say this is not valid? Probably. If the vector is empty then v[0] is an out of bounds access. | |
Re: Template parameters are not polymorphic that way. One way to do what you want is to put identifying information in the base class and require that information in the container class. [code] class Base { public: enum { BASE_TYPE }; // Identifying information virtual ~Base() {} }; class Derived : … | |
Re: Single quotes in a string should be fine, but you might need to escape the embedded double quotes. [code] string s = "L'Oreal assures us \"You're worth it\"."; [/code] | |
Re: > bobby = new int(numero); This dynamically allocates *one* int with the value of numero. Square brackets are used to allocate arrays. [code] bobby = new int[numero]; [/code] | |
Re: If j needs to persist between method calls, it should probably be a private data member instead of a local variable. | |
Re: > 1) How can I free the memory from main(). But the memory was allocated in function a(). If you do not have a pointer to the memory, it is lost. > 2) How can I return the local pointer variable? Your code is fine. Returning a pointer to dynamic … | |
Re: C# and C++ can both do these things, it is just a matter of how much work you are willing to put into writing the classes. | |
Re: Ctrl+Alt+Del is a secure attention sequence that cannot be intercepted by running applications. The whole point of a secure sequence is that one can be sure the OS is processing it rather than a malicious program. Edward cannot think of any benign reason why someone might want to disable it. | |
Re: > I can't determine how to specify the maximum number of characters to read. scanf() does not offer a user-defined field width like printf(). The way to make it dynamic is with sprintf. [code] char fmt[15]; char *data = malloc(n); sprintf(fmt, "%%dc", n); scanf(fmt, data); [/code] Why not just use … | |
Re: > Thats called hashing. Hashing is not guaranteed to produce unique codes except in special circumstances. The answer to this question really depends on what the code is used for. The needs of the program determine how the code is generated. For example, if the code is unique for each … | |
Re: memset() will fill an array with a value. If you need special logic to copy a value, then some kind of manual loop is pretty much the only way. | |
Re: Libraries have two parts. You have the header and included it in your code, but did you link with the built object file paired with the header? The object files for libraries on Linux are usually .so for static libraries. Your build command should look something like this for gsl. … | |
Re: > b) will my variable z go out of scope before it goes through the whole vector. No sir. The scope of z is the same as the scope of the vector, so as long as you can access the vector object, you can access z. :) > a) how … | |
Re: > This should cause a coredump or crash because it uses an uninitialized pointer Yes, but normally a static method is called using the class name when it cannot be called on an object. [code] A *a = A::create(); [/code] | |
Re: > way1 = temp; Edward will guess that way1 is declared as [code] CPoint way1[10]; [/code] Arrays in C++ are almost-but-not-quite first class types because they do not allow assignment. To copy items from one array to another, or from a dynamic array to a static array, each element must … | |
Re: Executable statements have to be inside of a function. These are the executable statements in your header file. [code] word_list->input = "a"; word_list[0].output = "b"; (word_list+1)->input = "c"; (word_list[1]).output = "d"; [/code] | |
Re: Local variables are destroyed when the parent function returns. In combine(), the r array is a local variable. Even if you return a pointer to it, the array will still cease to exist when combine returns. Two ways around that problem are passing a buffer and returning a pointer to … | |
Re: The golden rule is thusly: If you call malloc, calloc, or realloc, you must call free on the pointer returned or risk a memory leak. > 1) If I declare a variable in a block of code as a character array, I'm making a pointer to it. You are making … | |
Re: > how does the compiler, running program ? know how much memory to delete There is a lot of plumbing behind new that manages info like how many bytes are in an assigned block. delete uses that info to free the block. > why cannot the developer access that size … | |
Re: > 1. Is there a way, in C++ to do a do - if loop? You might need to explain how the logic of a do - if loop works. Edward can think of more than one way, but this one is intuitive. [code] if (condition) { do { // … |
The End.