2,898 Posted Topics

Member Avatar for luislupe

>>Can I build such a template? You cannot. The reason this is a problem (and the reason for the errors) is because your function template, when instantiated with int, has to compile, all of it has to compile, including the parts that will not be executed (i.e. parts which insert …

Member Avatar for mike_2000_17
0
329
Member Avatar for thedonflo

The reason why the code keeps repeating the first value all the time is because the first value "9" is the largest one, so it will be moving up the array as you are traversing it. If you want to print the original array, make a separate loop for that. …

Member Avatar for thedonflo
0
102
Member Avatar for jowana

To get the normal out of a vertex on the edge of a 2D polygon, you take the vector that goes from the point just before to the point just after, and then you rotate that vector by 90 degrees ccw (right-hand rule). You can do that by swaping (x,y) …

Member Avatar for jowana
0
119
Member Avatar for geekme

Definitely, [URL="http://www.codeblocks.org/downloads/26"]Code::Blocks[/URL] is recommended. It's the easiest one to download-install-setup-use with gcc (you should be able to pretty much compile and run a hello-world program within the minute following the install). As for GCC, the stable recent versions are good. I think the current release of CodeBlocks comes with GCC …

Member Avatar for mike_2000_17
0
163
Member Avatar for sha11e

Don't use setprecision if you want the computer to figure out the precision.

Member Avatar for sha11e
0
3K
Member Avatar for TheWolverine

You can use [URL="http://www.boost.org/doc/libs/1_46_1/libs/tokenizer/index.html"]Boost.Tokenizer[/URL]. It has nicer functions for extracting tokens from strings. You can, for instance, specify a list of characters that should be ignored and that mark the separation of tokens. This is the canonical example: [CODE] // char_sep_example_1.cpp #include <iostream> #include <boost/tokenizer.hpp> #include <string> int main() { …

Member Avatar for mike_2000_17
0
387
Member Avatar for dyingatmidnight

By the way, you have a memory leak in this queue class. I understand the garbage collector takes that responsibility off your back when in Java, but in C++, you are responsible for cleaning up your own mess, like grown-ups do. So, in the remove function, you need to delete …

Member Avatar for mike_2000_17
0
237
Member Avatar for eman 22

It surely is legal. In fact, you need to have exactly one function named main() when you build an executable. So, if you have a main function in several cpp files, you are in trouble. Usually, cpp files which are associated with a class or a set of utility functions …

Member Avatar for mike_2000_17
0
553
Member Avatar for geekme

If you are just interested in visualising a graph, why not use [URL="http://www.graphviz.org/"]graphviz[/URL]? It's a library dedicated to that very purpose. It will probably be easier to just shoot your graph structure into the graphviz functions and get some image files out, instead of using a full GUI tool.

Member Avatar for mike_2000_17
0
133
Member Avatar for WhiZTiM

>>What kind of bug do you classify the program's problem into? const-correctness. >>I plan to integrate a UI and upload it on sourceforge if I can It's good to do these little projects as learning experiences, but don't mislead yourself into thinking that this kind of code would be worth …

Member Avatar for WhiZTiM
0
293
Member Avatar for jimJohnson

line 56 is a simple typo. You declared and set a variable named checkWaitResult a few lines before but then use dwWaitResult. You just need have the same name in both uses. line 139 is reversed. When you use = sign, it stores whatever is on the right into the …

Member Avatar for mike_2000_17
0
150
Member Avatar for AliRaiz

There are no freebies here. We can help you if you show that you have done some efforts of your own and if you are stuck on some specific problem(s). Don't expect to just ask and get people to solve your homework assignments. That wouldn't be helpful to you, nor …

Member Avatar for mike_2000_17
0
521
Member Avatar for daviddoria

You need to omit the specialized type from the template <...> declaration. See my edit on your example. As here: [CODE] template<typename T> //the types in here are only those that are unknown. class Point<T, int> { void function1(); }; //similarly: template<> //no type is unknown (full spec.) but you …

Member Avatar for mike_2000_17
0
588
Member Avatar for Shruti4444

**Please use code tags** >>int findDuplicate(string a,string b) In C++, strings can be compared with ==. There is no need for this function. >>int i,j=0,flag=0; Declare your variables where you first use them, whenever possible. >>for (i=0; i<(int)stringTable.size();i++) Prefer iterators to indices when doing a simple linear traversal: [CODE] for …

Member Avatar for mike_2000_17
0
2K
Member Avatar for altXerror

The error comes from the fact that declaring a variable as extern does not "declare" the variable, it simply tells the compiler that there is a global variable with that name. Somewhere, you need to have a global variable with that name. You don't have that anywhere. You could just …

Member Avatar for altXerror
0
151
Member Avatar for flowerzink

Where is the copy-constructor in your Mascota class? That's the piece missing, and what an important one! I highly, highly recommend that you use std::string instead of char* and that you store the integer edad by value, not by pointer. Pointers are evil and you are suffering it right now. …

Member Avatar for flowerzink
0
256
Member Avatar for iamthesgt

Casting from int to enum just requires an explicit cast (it is meant to reduce unintentional (implicit) casts). Just use a static_cast. As so: [CODE] display.setMode(static_cast<VideoOutputMode>(atoi((**vout_mode).c_str()))); [/CODE]

Member Avatar for iamthesgt
0
3K
Member Avatar for arthurav

Definitely, it is the comparator that is not correct. It should be (strcmp() == 0) (strcmp returns 0 if the strings are equal). If you used a std::string, it would be even simpler.

Member Avatar for thekashyap
0
302
Member Avatar for Kadence

Well, first of all, my recommendation would be to throw away that incredibly stupid library that does this. I can't comprehend how retarded somebody must be to think that making a #define with the name "thread" is not going to cause tremendous name-clashes. Anyways, if you really have to use …

Member Avatar for Kadence
0
287
Member Avatar for stereomatching

Well, do you really have that many alternative strategies? For a test program like this, I don't see much alternative to just listing out the combinations and executing them one after the other. Anyhow, you could just make f, g, and h as static arrays of boost::function<> and loop through …

Member Avatar for stereomatching
0
121
Member Avatar for Kanoisa

Normally, you do need to lock both the reader and writer such that their operations are mutually exclusing (with a mutex or critical section(windows), personally I would recommend Boost.Thread since it uses the best mechanisms for whatever OS you use). And, if you lock all read and write operations, then …

Member Avatar for Kanoisa
0
659
Member Avatar for fibbo

This function: [CODE] std::vector<passenger*>& passenger_queue::passengers_at_floor(int floor_) const [/CODE] Has a big flaw, which results in the error you are getting. Since the function is const, it means that you only have read-only access to all its data members. But then, you try to return a non-const reference to a data …

Member Avatar for fibbo
0
7K
Member Avatar for stereomatching

I think that the easiest way to do it is to simply use a functor with both overloads. Something like this for example: [CODE] struct adaptSR_type { typedef int result_type; template<typename accStrategy> int const operator()(int const MAX_AL, float const CONFIDENT_LV, int const OFFSET, accStrategy PLAN) { return 1; } int …

Member Avatar for stereomatching
0
364
Member Avatar for lochnessmonster

My rule of thumb to decide whether to use free functions or class member functions is as follows. First of all, if you need to keep track of a state of some kind (like an opened file or array/vector or any other construct like that), then you need a class …

Member Avatar for mike_2000_17
0
116
Member Avatar for maybnxtseasn

I think that a good old dictionary can give you a pretty good start: "auxiliary" and "helper" are synonyms in English. And, as far as I know, they are synonymous in programming terminology as well. "Utility functions" are similar in some sense but slightly different. A "nonmember" function is obviously …

Member Avatar for mike_2000_17
0
142
Member Avatar for sergent

>>A dinosaur will pop out of your computer and eat you if you do. I wish it could be required by the C++ standard to devour any programmer who writes a "goto" statement. >>I don't understand why goto's are so bad. A goto statement is a relic from the times …

Member Avatar for arkoenig
0
547
Member Avatar for caut_baia

It's totally fine. In fact, it is a safe way to do it. But it is kinda useless as is, because if the caller has access to the vtable pointer (to look up the virtual call to func()), then it can also implicitly cast the object pointer or reference to …

Member Avatar for caut_baia
0
134
Member Avatar for jmalbornoz

If you are going to use a singleton, do it correctly. The code that L7Sqr posted has two big flaws: before calling instance(), the pointer "only_copy" is not necessarily NULL, and thus, the test (!only_copy) is likely to be false even on the first use of instance(); second, there will …

Member Avatar for jmalbornoz
0
3K
Member Avatar for zaneulhaq

There are two fundamental ways to do this (at least what I can understand of it, I think a more concrete example would be better): Composition and Inheritance. In the case you presented first (with A, B, C, and D), I think inheritance seems most appropriate (although the example is …

Member Avatar for Stefano Mtangoo
0
410
Member Avatar for thisischris

No. ICOL is not a global variable, it is a #define. A #define is basically just a token (i.e. ICOL) and an expression (i.e. 32). Basically, the preprocessor (a basic parser that looks at your code before it gets compiled) will look through all the code and do a basic …

Member Avatar for mike_2000_17
0
177
Member Avatar for goocreations

This is very weird. The problem must be a sort of stack wind-up of the for-loop (at low-level a for-loop is turned into a "label, set of instructions, and goto the start label", so if "set of instructions" increases the size of the stack you get a stack wind-up). But …

Member Avatar for mike_2000_17
0
124
Member Avatar for pdwivedi

The printf function is not type-safe (it is from C, which is only weakly typed). The printf interprets its parameter types (after the formatted string) based on the format values in the string. So, if you have %d in the string, it will interpret whatever the second parameter is as …

Member Avatar for mike_2000_17
0
604
Member Avatar for lochnessmonster

>>is there any additional overhead for the first case? Yes, of course. In the first case, you needlessly create an instance of the Log class. And then, when you call the member function, the this pointer is implicitly passed as a first "hidden" parameter to the function, so that's a …

Member Avatar for thekashyap
0
109
Member Avatar for fibbo

>>thinking about it made me come up with this. could this work? Yes it does. (well, you are missing one closing parenthesis) But, there is a better way. The problem with your implementation is that you are doing a lot of useless copying (you create a "large" vector and push …

Member Avatar for mike_2000_17
0
2K
Member Avatar for ztdep

When the const is at the leftmost place, it is attached to the return value. In that = operator, it means that the function returns a const reference to itself. When the const is at the rightmost place (after the parentheses), it is attached to the object to which to …

Member Avatar for mike_2000_17
0
184
Member Avatar for stereomatching

>>Do I need to pass it as arguments if I want to implement it by std::tr1::bind? If the AnyFunctor needs arguments when called, you need to get those arguments from somewhere. So the idea, like in your last piece of code, to create some temporary variable with some arbitrary value …

Member Avatar for stereomatching
0
135
Member Avatar for |Mike|

You should bundle the string and CGameSlot into a struct and make a list of those. Then, you can define the < operator such that structs are compared by the string. For example: [CODE] struct Struct1 { string User; CGameSlot PlayerSlot; Struct1(const string& aUser, CGameSlot aPlayerSlot) : User(aUser), PlayerSlot(aPlayerSlot) { …

Member Avatar for mike_2000_17
0
232
Member Avatar for pseudorandom21

Well, primitives are generally thread-safe just by the virtue of value-semantics and their primitive nature (as in, any read/write operation on them is atomic, i.e. it's extremely unlikely that a thread switch would occur in the middle of the operation, which is really where mutexes are required). For larger classes, …

Member Avatar for vijayan121
0
259
Member Avatar for pivotcity

Are you sure that this line: Calculate Deposit_Amount = (0.25*Loan_Amount) + $5,000 shouldn't be: Calculate Deposit_Amount = (0.25*(Loan_Amount - $50,000)) + $3,750 and similarly for the other ones. That would seem to make more sense to me (at least, that's how income tax is calculated). I mean, the deposit amount …

Member Avatar for pivotcity
0
186
Member Avatar for Khoanyneosr

The win32 API requires wide-char strings. You need to add a leading L in front of the literal string to tell the compiler to create a wide-char literal string: [CODE] windowClass.lpszClassName = L"WindowClass"; //notice the L in front. [/CODE] And similarly for the other place where the error occurs.

Member Avatar for Khoanyneosr
0
138
Member Avatar for SeePlusPlus2

aPtr is a pointer to an array of "double" variables. When you want to copy one NumberArray object into another, the new object has to allocate a new array of doubles which can contain as many elements as the other object, and then copy all the elements from one array …

Member Avatar for mike_2000_17
0
117
Member Avatar for nihaS

This, to my knowledge, is not a particularly common pattern, especially in OOP. It is, however, somewhat ubiquitous in Generic Programming (which can be used alongside OOP). In OOP, I think they are mostly referred to as [I]mixins[/I] (as in, mixing in different classes to make a sort-of bast_ard superclass). …

Member Avatar for rubberman
0
1K
Member Avatar for v_janssens

First, the way that you can test whether you have run out of memory in the program is to check that the pointer you get from malloc is not NULL. This pointer will be NULL if you are out-of-memory. This is also why you get the error of dereferencing a …

Member Avatar for v_janssens
0
464
Member Avatar for Labdabeta

There are a few options. But this is a classic problem with templated code. For instance, the STL libraries are not compiled (so basically, standard C++ libraries are open-source). The first option is to put all the definitions of the member functions inside a .cpp file and #include the cpp …

Member Avatar for Labdabeta
0
100
Member Avatar for Ancient Dragon

>>I am not clear as to what a seed is I think the easiest way to think about it, from a beginner's perspective, is that, since a computer is deterministic (it can't actually produce truly random numbers), the best it can do is use a formula that produces "very wacky" …

Member Avatar for Ancient Dragon
0
372
Member Avatar for Lusiphur

Well, I did a bit of image processing, so I know the basic theory. I can't explain it all but I can give some keywords and methods for you to look up. First, the problem of resolution, cropping, geometric disturbance (rotation translation scaling etc.) is pretty trivial to solve really. …

Member Avatar for arisa12
0
717
Member Avatar for Unseen Machine

This is the usual loop to use: [CODE] #include <fstream> #include <iostream> #include <vector> using namespace std; //define your SalesRecord. int main() { vector<SalesRecord> data; //storage for all the SalesRecords. ifstream CheckFileStream; CheckFileStream.open("SalesRecord.txt",ios::binary); if(CheckFileStream.is_open()) { SalesRecord tmp; //temporary storage for the one element to be read. while(CheckFileStream.read((char*)&tmp, sizeof(SalesRecord)) data.push_back(tmp); //adds …

Member Avatar for mike_2000_17
0
344
Member Avatar for Smartflight

>>I am not clear as to what a seed is I think the easiest way to think about it, from a beginner's perspective, is that, since a computer is deterministic (it can't actually produce truly random numbers), the best it can do is use a formula that produces "very wacky" …

Member Avatar for Smartflight
0
267
Member Avatar for sha11e

I can't answer those questions directly because they sound too much like assignment questions and you shouldn't be given a freebie (it would help you to learn). However, I can correct some of your underlying misconceptions. >>I've seen some that have 6 characters after the 0x and some that have …

Member Avatar for rubberman
0
215
Member Avatar for stavros141

First of all, this is highly dependent on the capabilities that you want your plugin system to be able to handle. It can range from a very simple set of capabilities, leading to a fairly easy task to accomplish, to a very comprehensive set of capabilities, leading to a very …

Member Avatar for stavros141
0
191

The End.