2,898 Posted Topics

Member Avatar for Sonia11

>>to use even more stl, To use even more STL, with C++0x: [CODE] #include <vector> #include <algorithm> #include <functional> #include <iostream> int main () { using namespace std; std::vector< int > items; for (int i = 0; i < 25; ++i) items.push_back (i % 3); std::map<int,int> counts; std::for_each( items.begin(), items.end(), …

Member Avatar for L7Sqr
0
4K
Member Avatar for awah mohamad

>> i have problem compiling this code Post the compilation errors. You may not understand them, but we do. It is hard to know the error, especially since you are using a lot of non-standard functions and headers (gotoxy(), randomize(), random(), clreol(), etc.).

Member Avatar for awah mohamad
0
707
Member Avatar for riotburn

Your expression "shapes[i] - shapes[1]" takes the difference between the two pointers, not the two objects. You need to dereference the pointers before you apply the difference operator. As so: [CODE] *(shapes[i]) - *(shapes[1]) [/CODE] Also, I would suggest you make your operator - a friend function instead of a …

Member Avatar for mike_2000_17
0
186
Member Avatar for mike_2000_17

[B]Beginner's Guide to C++0x: The Big Five - Implementing a Resource-holding RAII Class[/B] This tutorial will show how to implement a [I]resource-holding class[/I] showing practical use of [I]C++0x features[/I]. A resource-holding class is any class which holds, with its data members, a resource which could include: [LIST] [*]dynamically allocated memory …

17
3K
Member Avatar for thecoolman5

You probably need to use an external library of some kind. [URL="http://freeimage.sourceforge.net/"]FreeImage[/URL] is one which is easy to use, supports most standard image formats and allows you to do some basic transformations on them. If you want to do more advanced transformations on the image, then you can use [URL="http://opencv.willowgarage.com/wiki/"]OpenCV[/URL]. …

Member Avatar for mike_2000_17
0
332
Member Avatar for bratok

>>Or am i making this way harder than it should be? Seems like a totally reasonable approach. But if you read one string at a time, the default behavior is to read a word at a time. Read each word, check for being "T" or "H" or other (invalid input), …

Member Avatar for bratok
0
244
Member Avatar for bimoweemo

You cannot (easily) separate the implementation and the declaration of a template. The compiler needs to have access to the implementation in order to instantiate the template for a given set of template-arguments. [URL="http://www.parashift.com/c++-faq/templates.html#faq-35.12"]Read this[/URL]. Simply put all your implementations in the header file (either inside the declaration of the …

Member Avatar for mike_2000_17
0
204
Member Avatar for L3gacy

First of all, the istream iterator gets initialized at the line 18, and so does the end iterator (default-constructed iterator marks the end). Second, the while loop simply iterates until begin reaches the end of the input. That is what the [ICODE](begin != end)[/ICODE] condition verifies. Third, the [ICODE]*begin++[/ICODE] dereferences …

Member Avatar for mrnutty
0
323
Member Avatar for RAIMI
Member Avatar for RAIMI
0
307
Member Avatar for vinothcv

This forum is not a repository for posting homework assignment questions. We don't do your homeworks for you, it is not in your interest or anybody else's. Try to solve the problem yourself, and if you have problems with [B]specific[/B] things, post them back here, show [B]your[/B] code that demonstrates …

Member Avatar for Salem
-1
518
Member Avatar for salah_saleh

It gives the reason why directly above the function definition: [CODE] 45 // utility function called by insertNode; receives a pointer 46 // to a pointer [B]so that the function can modify pointer's value[/B] [/CODE] If you simply pass the rootptr, any modification to the root-pointer with the function will …

Member Avatar for salah_saleh
0
156
Member Avatar for rayden150

Don't use the standard libraries with the .h extension, they are out-dated (pre-1998) and are only kept around for backward compatibility and I wouldn't expect them to be updated to work fully on newer implementations (OS). Use the following headers instead: [CODE] #include <iostream> #include <string> #include <cstdlib> #include <cstdio> …

Member Avatar for mike_2000_17
0
256
Member Avatar for bimoweemo

Sure, why would you not be allowed to? Are you talking about several functions with the same name (overloads). Then, yes, you are also allowed to mix function template and normal functions, even when overloading (but you should avoid specializing function templates if you provide other overloaded functions, that's the …

Member Avatar for bimoweemo
0
117
Member Avatar for MareoRaft

>>And of course, is it WORTH passing ints by reference? Certainly not by const-reference. Ints, like pointers and references, are usually of the native word size of the computer, which is 32bit or 64bit on most PCs. So, making a new int variable (i.e. copying it) and passing it by …

Member Avatar for mike_2000_17
0
300
Member Avatar for MareoRaft

>>Why is it a bad idea to use the std namespace for my new functions? You should not put anything in the std namespace. There are only very rare (and advanced) reasons to put anything in the std namespace. And there is nothing special about the std namespace in this …

Member Avatar for mrnutty
0
150
Member Avatar for bigdan182

I would make a class to store all the information relevant to a team, with some member functions to manipulate that data. For example: [CODE] class Team { public: std::string name; std::vector<Player> players; int current_standing; //... }; [/CODE] I would probably suggest you store the data in a [URL="http://www.cplusplus.com/reference/stl/map/"]std::map[/URL] which …

Member Avatar for mike_2000_17
0
221
Member Avatar for Jsplinter

While you are using C++0x, then you might as well do: [CODE] my_list.remove_if( [](int x) -> bool { return x == 4; } ); [/CODE]

Member Avatar for Narue
0
233
Member Avatar for daviddoria

I agree with Narue. Collecting a bunch of "fundamental" types into one header file is fairly common, as long as those types constitute a cohesive group of related types. The fact that you cannot find a better name than "types.h" sort-of hints to the fact that they do not form …

Member Avatar for mike_2000_17
0
134
Member Avatar for dyingatmidnight

You have one too many parenthesis on line 10, it should be: [CODE] float K5 = ((k0 * nu * pow(cos(lat),3))/6) * (1 - pow(tan(lat),2) + (esq * pow(cos(lat),2))); [/CODE] Notice that there is no parenthesis just before [ICODE]pow(tan(lat),2)[/ICODE], this was causing the subtraction to distribute over the next term, …

Member Avatar for dyingatmidnight
0
2K
Member Avatar for thecoolman5

Lets see what your code does, and clarify it. [CODE] int l = 1; for(l = l; l > 0; l--) [/CODE] The statement [ICODE]l = l[/ICODE] is useless, it does nothing. Replace it with the previous line. [CODE] for(int l = 1; l > 0; l--) [/CODE] Now, it …

Member Avatar for mike_2000_17
0
1K
Member Avatar for MareoRaft

Just a thought: >>I am building a library of matrix and vector operations. >>then I must write a function for each of those operations. It seems odd to me that you are building a library for matrix and vector operations and you are complaining that you need to write all …

Member Avatar for mike_2000_17
0
153
Member Avatar for sha11e

The form [ICODE]std::string test("hello");[/ICODE] is called a "direct-initialization". This is essentially a direct call to whatever constructor matches the parameters given. Direct-initialization is the only accepted form in a class constructor's initialization list. The form [ICODE]std::string test = "hello";[/ICODE] is called a "copy-initialization", because it is meant as a initialization …

Member Avatar for Narue
0
102
Member Avatar for munitjsr2

Q1)Can we delare constant data members inside a class? Yes. As a static member with inline initialization if it is a integral type or with a definition statement outside the class if it is not an integral type. As a non-static member, you need to initialize the data member in …

Member Avatar for kanuxy
-2
185
Member Avatar for u8sand

nmaillet is correct. But in response to: >>Also if you see anything in my code that needs to be fixed feel free to tell me about them. I don't see anything that _needs_ to be fixed, but certain things could be made better. First, think hard before you use the …

Member Avatar for mike_2000_17
0
249
Member Avatar for thecoolman5

All you need is to rewrite the value with 2 digit precision after the dot. Look at [URL="http://www.cplusplus.com/reference/iostream/manipulators/setprecision/"]setprecision[/URL]. There are examples that do exactly what you need. Just read the numbers from the input file, and write them to the output file with the setprecision functionality.

Member Avatar for m4ster_r0shi
0
467
Member Avatar for winecoding

The STL stands for Standard Template Library. Like any other template library, it is a header-only library (except for some low-level things, maybe). You already have the source if you have the headers, just look for them. Under linux, they will be either in /usr/include/c++ or /usr/local/include/c++. Under windows, it …

Member Avatar for alwaysLearning0
0
433
Member Avatar for tikoti

Is there a reason why you are using such an old compiler? I'm sure that red-hat has some more recent package of GCC available. And yes, you need the function AccumSq to be declared sometime before you use it.

Member Avatar for tikoti
0
276
Member Avatar for ztdep
Member Avatar for mike_2000_17
0
82
Member Avatar for perfectBing

>>Is it mandatory to Use static functions for a Singleton class. I guess you could make a poor implementation of a singleton without a static function, but it is not usual or recommended. Usually the two options are a static function or a free function (non-member function). The implementation that …

Member Avatar for alwaysLearning0
0
85
Member Avatar for ravenous

From the print out, it is clear that the stride is correct, so the use of M_pGSLData->tda is not going to solve the problem, although it is recommended to use that value and not assume another (like M_uCols). Clearly, the value of the pointer M_start is being set to the …

Member Avatar for ravenous
1
384
Member Avatar for Ana_Developer

hash_map is deprecated. You should use [URL="http://en.cppreference.com/w/cpp/container/unordered_map"]unordered_map[/URL] instead. It is a C++0x standard feature, but most compiler vendors support it already, without having to compile with the C++0x experimental support flag. Other than that, I am not familiar with std::hash, so I don't know how to solve your problem. But …

Member Avatar for mike_2000_17
0
151
Member Avatar for TheWolverine

Well, using shared_ptr is definitely the best thing to do in this case (I use them a lot for these kind of cases). The way to have the life-time of the object under your control is to dynamically allocate it and thus, deallocate it when it should. The problem is …

Member Avatar for TheWolverine
0
403
Member Avatar for mchin131

The parameters of a function only exist as long as the function is executing. When the function has finished, its parameters disappear. They don't need to be "reset" before the second call. When you call the function, you provide the arrays it should work on, and the second time you …

Member Avatar for mike_2000_17
0
258
Member Avatar for tomtetlaw

First, in response to thelamb and JasonHippy, dynamic_cast is not needed in this case, and if you have created the CVSystemDLL class in a separate DLL, then dynamic_cast will not work in the exe (if that is what is being done). Second, >>If it's related to the problem, the code …

Member Avatar for tomtetlaw
0
2K
Member Avatar for gujinni

>>Why do you ask? Because it is a homework problem in which the prof said not to use STL algorithms, I guess. This is a typical homework problem to teach people how to do basic string or array manipulations. Ironically, it is also a typical interview question to see if …

Member Avatar for gujinni
0
190
Member Avatar for pseudorandom21

I have not heard or seen any book or resources online which are a "generic guide to using external libraries in C++". I think the problem with writing such a guide is the shear amount of possibilities. There are APIs, header-only libraries, source-file-only libraries, different programming paradigms, some have special …

Member Avatar for Ancient Dragon
0
3K
Member Avatar for confused_one

LOL! @WaltP: Pretty good timing for this thread! Don't you think? Yet another example of "I compile this with DevC++ and it doesn't work, but it works with other IDEs like ..". @OP: I agree with both posters. Stick to one generation of C++ code, that is, the current standard, …

Member Avatar for Stefano Mtangoo
1
4K
Member Avatar for CPT

Examples of real serialization methods or libraries are: [URL="http://www.boost.org/doc/libs/1_46_1/libs/serialization/doc/index.html"]Boost.Serialization[/URL] [URL="http://code.google.com/p/protobuf/"]Google's protobuf[/URL] [URL="http://www.json.org/"]JSON[/URL] Serialization requires two things: a way to deconstruct an object tree into a buffer from which the tree can be reconstructed (which usually requires some form of type identification), and a way to read and write the buffer …

Member Avatar for mike_2000_17
0
176
Member Avatar for learningcpp

@m4ster_r0shi: >>Something like this would work fine: (overloading operator >>) I should point out that operators >> and << are left-associative, so overloading operator >> like you did is going to be problematic when combining several calls. So, this is not recommended, especially since it inverts the normal semantics of …

Member Avatar for m4ster_r0shi
0
350
Member Avatar for pseudorandom21

>>Definitely a bunked include path Try to locate the header files manually in the hard-drive. Possibly, add all the sub-directories to the include path list. Make sure you have all the dependencies met.

Member Avatar for Celtrix
0
257
Member Avatar for vergil1983

>>Anyone can share their knowledge here?? First of all, don't expect this approximate series to give reasonable results for x > 1.0 (and less than -1, of course), there are theorems that prohibit that. Also, you need to compile with highest optimization level for this kind of applications. I actually …

Member Avatar for deliezer
0
3K
Member Avatar for deliezer

This really is eating me inside because I remember seeing the exact same symptoms in a project. It was a very long time ago, and I'm having trouble remembering what the problem was, but I do remember it was painful to find. I can at least say a few things: …

Member Avatar for deliezer
0
91
Member Avatar for WaltP

>>CB current version is 10.5 and is distributed with gcc version 4.4.1 copyright 2009. Is that not the same as current version of MinGW without CB? The current release version of GCC is, of course, 4.6.1 (from June 27 2011). Of course, it takes a little while longer to get …

Member Avatar for pseudorandom21
0
1K
Member Avatar for sadsdw

The problem is clear, and has been answered already. std::bad_alloc is the exception that is thrown when dynamic memory allocation fails. Generally, the most likely reason why dynamic allocation can fail is because it would require more memory than you have available on your computer. When allocating a 150,000 x …

Member Avatar for sadsdw
0
2K
Member Avatar for lenzo

You can use Qt. Do this in a terminal window: [CODE] $ sudo apt-get install libqtcore4 libqtgui4 libqt4-dev qt4-qmake qt4-doc qt4-demos qt4-assistant qt4-designer qtcreator qtcreator-doc [/CODE] Some of the above might be redundant, but what the heck. And most of it is probably installed already as part of the distro …

Member Avatar for Celtrix
0
294
Member Avatar for TheLittleEngine

>>ok so i'll always need a default constructor even when i add other constructors You can do both at the same time using default parameters, this is very common. For example, consider this simple class that represents a 2D vector: [CODE] class Vector2D { public: double x,y; //two data members …

Member Avatar for Stefano Mtangoo
0
214
Member Avatar for NathanOliver

The best for C++0x right now is certainly GCC 4.6.1. If you are willing to build from source (which could be pretty hard for Windows), then you can also use 4.6.2. The current development version is 4.7.0, but it is experimental, and from personal experience with it, I don't recommend …

Member Avatar for NathanOliver
0
367
Member Avatar for tomtetlaw

The answer is: - I don't know. - [URL="http://www.boost.org/doc/libs/1_46_1/doc/html/program_options.html"]Boost.Program-options[/URL] - [URL="http://www.boost.org/doc/libs/1_46_1/doc/html/date_time.html"]Boost.Date-time[/URL] Let me elaborate: For the first problem, "IsDebuggerPresent", it is the first time I hear of such a function, I have no idea if it has or can have an equivalent in Linux. As far as I know, you …

Member Avatar for mike_2000_17
0
201
Member Avatar for Fatooma

You forgot to implement the assignment operator, which usually implies implementing a swap function as well. As so: [CODE] class Street { private: int stretNumber; string name; int numberHouses ; int *ListHouses ; public : Street(); Street(int, string, int); //Street(const Street & otherStreet); Street(const Street & Street1); void destroyHouses(); void …

Member Avatar for mike_2000_17
0
151
Member Avatar for airerdem

As m4ster_r0shi said, you can use a different comparator to get a descending order for the sorting. I would just add that you can use the standard one instead of a custom compare() function, as so: [CODE] std::sort(fitness, fitness + 250, std::greater<double>()); //the default comparator is 'std::less<double>()' [/CODE] And yes, …

Member Avatar for mike_2000_17
0
138

The End.