2,898 Posted Topics

Member Avatar for David_Omid

I'm not sure, and I'm not so familiar with C++/CLI (which is not the same language as C++). But what if you reach the line below, while a is still equal to -1. I think there is a slight chance that it does, so you might want to do a …

Member Avatar for David_Omid
0
216
Member Avatar for Logert

If you look at the [URL="http://eodev.sourceforge.net/eo/tutorial/html/FirstRealGA.html#evalfunc"]code of tutorial 1[/URL] for a real-valued problem, from the EO homepage. You see the very first function called "real_value". This calculates the fitness value for an individual. You can reprogram that function to do whatever you like. In your case, it should (somehow) give …

Member Avatar for mike_2000_17
0
217
Member Avatar for vddmanikanta

[URL="http://programmingexamples.net/index.php?title=CPP/Classes/Singleton"]This[/URL] is the basic singleton implementation. (I'm giving the link because, if you are going to look on the internet to find a copy-pastable implementation of it, you might find a poor one (like the one from AndySpb) and screw your code up with it, so at least, this link …

Member Avatar for mike_2000_17
0
170
Member Avatar for Crutoy

>>i lose the newly allocated space. Exactly. If you set p = monster, you will lose access to the memory that was allocated before. But worse, you can no longer delete the memory you had allocated before (because you no longer have the address to it), this is called a …

Member Avatar for lisaroy1
0
305
Member Avatar for megaLU

I think you need to post the entire code, maybe you did something a little weird that upset the compiler. Otherwise, this shouldn't cause an error.

Member Avatar for jonsca
0
2K
Member Avatar for lius84

First, your statements: [CODE] delete [] KernelGaussian[0]; [/CODE] are not correct, you need to traverse the array of pointers and delete each one of them, as so: [CODE] for(int i=0;i<POINTS_VERY_FEW;++i) delete [] KernelGaussian[i]; [/CODE] Second, you should set all the pointers to NULL after you free them and check that …

Member Avatar for mike_2000_17
0
181
Member Avatar for winecoding

The original means: Return a reference to the smallest of two variables from the caller's scope. The first revision means: Return a reference to the smallest of two temporary variables that will go out-of-scope as soon as the function returns. (i.e. This is an ERROR! This will lead to undefined …

Member Avatar for mike_2000_17
0
123
Member Avatar for MasterGberry

Read [URL="http://en.wikipedia.org/wiki/Big_endian"]this[/URL]. Then [URL="http://www.cplusplus.com/doc/tutorial/variables/"]this[/URL] (especially the note about sizes of integers in C++ which are dependent on the system you use).

Member Avatar for MasterGberry
0
508
Member Avatar for Fjolsvidr

I can't give you much book suggestions or basic online tutorial (because my years of learning basic C++ are far behind me), but there is one site (in addition to [url]www.cplusplus.com[/url]) that is key resource for understanding and knowing how to program well, that is: [url]http://www.parashift.com/c++-faq-lite/[/url] As for learning C …

Member Avatar for mike_2000_17
1
128
Member Avatar for MasterGberry

I don't know about that problem about the size of the file. I would suggest you step through the code and/or print out the sizes of all there arrays (size of outTables, outTable.Items, and outItem.Data) to see if the problem is with the file stream or with the construction of …

Member Avatar for MasterGberry
0
134
Member Avatar for andrewkim

Your .c file is totally fine. The problem is your header file. You shouldn't include the .c file from the header. This causes a circular pattern that will recurse infinitely (.c includes .h includes .c includes .h includes .c ... ad infinitum). Your compiler simply stops this at some limit …

Member Avatar for mike_2000_17
0
112
Member Avatar for Majabat

Well, as a basic-level solution, yours is totally fine. It is _correct_ in the sense that it will do what you expect and without error. It is _ok_ in the sense that since you are stuck with code that you cannot or don't want to change that needs regular arrays, …

Member Avatar for Majabat
0
159
Member Avatar for nathanw

Welcome to Daniweb! Please use code-tags around the code that you post. I don't know where you saw that problems can occur when you have too many semi-colons. Usually, it is the other way around. Many stupid little compile errors can be solved with adding semi-colons. Usually, it is safer …

Member Avatar for jonsca
0
214
Member Avatar for MasterGberry

If test is a std::string, then you don't need the first comparison with NULL. This comparison is only needed if test is a "char*" (i.e. a null-terminated C-string), and in that case, it wouldn't be done that way. So, the two options are: C++ style string: [CODE] std::string test = …

Member Avatar for MasterGberry
0
650
Member Avatar for MasterGberry

There are a few inefficiencies about your implementation (the push_back() is only one of them). Basically, you should avoid allocating memory within a loop. This is why push_back is inefficient because it re-allocates and copies the memory at each iteration (although STL containers like vector are amortized, but still..). Also, …

Member Avatar for MasterGberry
0
152
Member Avatar for cppgangster

You forgot to take the address of the functions. Your lines 32 and 34 should be like so: [CODE] trimr(s, &isspace); // notice the & trimr(s, &iswspace); // notice the & [/CODE]

Member Avatar for vijayan121
0
191
Member Avatar for TheWolverine

I think your application would be better (or more easily) solved with the use of dynamic polymorphism. Consider something like this: [CODE] //SOLVER_BASE_H #ifndef SOLVER_BASE_H #define SOLVER_BASE_H // Forward declaration. class MathematicalMethods; class SolverBase { protected: virtual double computeValue( double& value ) = 0; //pure virtual function in the base …

Member Avatar for TheWolverine
0
95
Member Avatar for MasterGberry

It would be: (don't use firstPerson's code, its faulty.. sorry fP..) [CODE] int main(){ unsigned char c1 = 0x56; unsigned char c2 = 0x78; unsigned char c3 = 0x92; unsigned char c4 = 0xF0; int combined = ((c1 << 24)| (c2 << 16) | (c3 << 8) | (c4 << …

Member Avatar for MasterGberry
0
214
Member Avatar for namelyia

A few observations: 1) You shouldn't use headers like <string.h> or <time.h>. These are deprecated. You should use <cstring> and <ctime> instead (notice "c" in front, and no ".h"), these are versions of the same old libraries but that will compile more easily with C++ code and compiler. 2) In …

Member Avatar for namelyia
0
268
Member Avatar for rebellion346

[QUOTE]different return types be supported by one function so you can use int, float, double, etc vs making several of the same function with different return types.[/QUOTE] Your definition of the use of templates is completely wrong (or at least extremely reductionist). First of all, what you are describing is …

Member Avatar for mike_2000_17
0
124
Member Avatar for TailsTheFox

If you are using Windows, i.e. Win32 API, then you can use the following function (as suggested before): [CODE] MessageBox(NULL,"An error has occurred because you didn't use this program correctly!", "Error!", MB_OK); [/CODE] If you need something more fancy (like different buttons or display), then you can make your own …

Member Avatar for TailsTheFox
0
4K
Member Avatar for mikecolistro

You made a typical logic error. Your algorithms for min is inverted. That is, your min function will actually return the maximum value. Just change the name and you have the max function done. The little bit of logic confusion is that when you are looking for the minimum, you …

Member Avatar for ravenous
0
168
Member Avatar for SpecialForce

Check the compatibility. [URL="http://msdn.microsoft.com/en-us/library/h9t88zwz%28v=vs.71%29.aspx"]fwrite[/URL] is "deprecated" on newer versions of windows. That might be the problem that causes the crash. Maybe running in compatibility mode or changing to code to use ofstream instead of fopen/fwrite.

Member Avatar for mike_2000_17
0
1K
Member Avatar for imolorhe

This scenario you are describing is classic in concurrent programming. Most of the time it is referred to as the consumer-producer scheme or just called a buffer between two processes. For multi-threading, I highly recommend using the [URL="http://www.boost.org/doc/libs/1_45_0/doc/html/thread.html"]Boost.Thread[/URL] library. It is very nice and easy and it will form the …

Member Avatar for mike_2000_17
0
196
Member Avatar for rcmango

If you see a class template declared as so: [CODE] template <class SomeType> class Foo { //... }; [/CODE] It means that to use this class, you need to provide another class (or type in general) as argument to the template. The STL queue type is similar (except that it …

Member Avatar for rcmango
0
530
Member Avatar for insanely_sane

Dev-C++ is outdated. The version of GCC that comes with it is 3.4! The current version of gcc is 4.4.5. We have also encountered several people posting threads on this forum about problems related to DevC++, including compatibility issues with the newer versions of Windows (Vista and 7). So I …

Member Avatar for mike_2000_17
0
194
Member Avatar for caut_baia

What should go in the cpp file is the following: [CODE] template <DWORD Style,LPSTR Type> WndObj<Style,Type>::WndObj () {}; //Definition or implementation of constructor. template class WndObj<>; // Explicit instantiation of the default template. typedef WndObj<> Button; //whatever this is.. doesn't matter. [/CODE] The point is that if you want to …

Member Avatar for mike_2000_17
0
109
Member Avatar for PhysicsExpert

It looks like you have a fixed number of elements in the table and they are simple bool type. I would suggest you use either a static array or a class vector instead of list. The error you are reporting is weird... normally, this should execute just fine. The error …

Member Avatar for PhysicsExpert
0
813
Member Avatar for v_janssens

I'm assuming that you know that when you click on "run" in VS, all it does is compile your project into a .exe, that you can find somewhere in your project folder, and then executes it. Finding that exe and double-clicking on it will run it "outside" VS. But that's …

Member Avatar for v_janssens
0
3K
Member Avatar for ctyszkiewicz

You have to also add the libb.so to the compilation of atest. Use the following command line to compile atest: g++ -Wall -L/vol/cuma/sandbox atest.cpp -la -lb -o atest Notice the addition of -lb

Member Avatar for ctyszkiewicz
0
151
Member Avatar for saleh-elyani

Look at all the variables that are used by your functions and put them as parameters. One (retarded) way to do this is to try and compile the code without any parameters to the functions. Then the compiler will throw a bunch of errors like "ErrorZZZZ: in function 'yyyy': identifier …

Member Avatar for saleh-elyani
0
160
Member Avatar for Hand

Read [URL="http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.14"]this[/URL]. In the link you will find a good enough explanation why it is not good to throw pointers. My take on it is: What if the dynamic allocation fails and throws an exception of its own? Basically, in that case, you will never reach the actual throw statement, …

Member Avatar for mike_2000_17
0
133
Member Avatar for MasterGberry

>>ReadUInt32() is a 4 byte integer, right? So technically I am reading 4 bytes into table.Type? Or does it do something else? If you need integer types of fixed length, you should use stdint.h or cstdint (depending on what your compiler can support). Check [URL="http://stackoverflow.com/questions/911035/uint32-int16-and-the-like-are-they-standard-c"]this SO thread[/URL] on the subject. …

Member Avatar for MasterGberry
0
161
Member Avatar for OpenSDL

>>How can I draw the quad to a SDL_Surface or a GLuint(texture), so I can combine them later? I don't know exactly how to do that, but I know it is not the best/easiest way to do it (in fact, it is probably the worst way). What you want to …

Member Avatar for mike_2000_17
0
286
Member Avatar for lochnessmonster

>>or is it wiped clean when it is restored back to the O/S for use? No, it would be wasteful to "clean" the memory. In fact, what does "clean" really mean.. setting all bits to 0? or to 1? or to some other pattern? The next process or chunk of …

Member Avatar for mike_2000_17
0
122
Member Avatar for roseworld

An HMM is just a model, not an algorithm. What is the task you want to accomplish? Feature detection, object tracking, mapping, compression, etc. ? Your best bet when it comes to vision stuff is [URL="http://opencv.willowgarage.com/wiki/"]OpenCV[/URL]. If this library does not have the algorithm or method you want, chances are …

Member Avatar for roseworld
0
224
Member Avatar for kikirkou

When an object is create, that is, at run-time, all the methods already exist (they are created at compile-time). Those 4 answers make no sense that way. If you create an object, why would it need to create its constructors? It can only be created once. Either the question is …

Member Avatar for Narue
0
126
Member Avatar for Wej00

This is a huge design issue. I will try my best to keep it brief. I will go from worse to best options, in my humble opinion (from experience in making a few simple computer games and having incrementally implemented a better solution each time). Global variables are horrible.. even …

Member Avatar for Banfa
0
1K
Member Avatar for BigDeveloper

Line 21 should be: [CODE] return sum (num->next, s*10+num->value); //value, not data. [/CODE] Other than that, I think it should work and do what it is supposed to do. Please give specific errors that the code produces.

Member Avatar for BigDeveloper
0
147
Member Avatar for Kakashi Hatake

Fundamentally, a running application is made of data and processes to manipulate that data. A program to solve a problem is made of sub-programs to solve the sub-problems. OOP is just merging those two realities by bundling data and the related functions in one entity (an object) that serves to …

Member Avatar for mike_2000_17
0
202
Member Avatar for seanbp

Your question is too vague and I think arkoenig and firstPerson's answers are quite good instructions for the "generic" small-code performance testing and optimization. Overall, people usually talk about three levels of optimization: macro-, micro-, and nano-optimization. You want to proceed through them in that order. Macro-optimization is about defining …

Member Avatar for vijayan121
0
107
Member Avatar for miturian

There are several options for this problem (which is quite usual in numerical simulation code.. where to put the simulation parameters?). I could suggest two that seem to stick out for me: 1) Make a POD-style class (e.g. C-struct) that has all the parameters: [CODE] struct SimulationSettings { a, b, …

Member Avatar for mike_2000_17
0
187
Member Avatar for mbouster

Please don't do what AD suggested (sorry AD..)! That is dangerous, unstable, and bad style. Unless the classes are all POD classes without virtual methods, this saving method will crash when you try to load the file again. What you are trying to do is called serialization. There are several …

Member Avatar for Tellalca
0
210
Member Avatar for svatstika

>>I've never seen how does type int look like? Neither did I. int is a primitive or built-in type. This means you won't find anywhere in the standard libraries an actual definition of int (like "class int { ... }") because the definition of the type is built into the …

Member Avatar for mrnutty
0
213
Member Avatar for losh177

Here is what my eagle eye has found: At line 17 of holding.cpp At line 26 of book.h At line 30 of record.h In all those cases, you have the same misplaced parenthesis: [CODE] //you wrote: title = new char[strlen(Hold.getTitle() + 1)]; //when it should be: title = new char[strlen(Hold.getTitle()) …

Member Avatar for losh177
0
103
Member Avatar for seanbp

Here is how it should work: [CODE] void expand() { int oldlen = actual_len; actual_len += increment; DynamicType* temp = new DynamicType[actual_len]; DynamicType* temp_begin = temp; data = data_begin; for (int i = 0; i < oldlen; i++) { temp->what_type = data->what_type; if (temp->what_type == temp->is_int) temp->integer = data->integer; else …

Member Avatar for seanbp
0
111
Member Avatar for MairiRobertson

I think it depends on your level of skill and what kind of projects you do. I can only give you my perspective on the ones that I am familiar with: Eclipse: I had to use it for a class (in Java) and have used the C++ version a little …

Member Avatar for mike_2000_17
0
163
Member Avatar for ChristinaS

It seems Clinton has got you well covered, but just to correct something.. I'm 100% sure that for this emboss function, you need to start from the upper left corner such that you don't use modified pixel values. Say you start from the last non-bordering row of the image, when …

Member Avatar for Clinton Portis
0
206
Member Avatar for shamsu50

You should get rid of lines 9 to 13 in sql.h. Do not import namespaces in a header file! You are polluting the name space and you run into the risk of name clashes. When someone includes your header file in their project, all of a sudden, they have imported …

Member Avatar for mike_2000_17
0
131
Member Avatar for DaSpirit

I don't know about the memory leak (I would assume it is just a natural growth of the heap.. wouldn't worry about it too much). What you are rendering is so trivial that you probably don't need VBOs (they are more critical when rendering meshes, e.g., a large complex model). …

Member Avatar for mike_2000_17
0
623

The End.