2,898 Posted Topics

Member Avatar for daviddoria

Hey David! I know you solved it, but if you want a more generic solution, I can suggest something. This case is a very good example of when traits can be very useful. Consider this: [CODE] //define a type trait for images: template <class T> struct image_trait { typedef typename …

Member Avatar for daviddoria
0
169
Member Avatar for Spiffy P Mcgee

Basically, a constant (like "const int some_constant_value = 42;"), whether it is at global scope, namespace scope, or a static data member, has to be assigned to a value that can be resolved at compile-time regardless of when it is initialized. So, this excludes any variable that is not also …

Member Avatar for mike_2000_17
0
115
Member Avatar for lotrsimp12345

For the record, I'm not an expert on Hopfield nets (but have dealt with other types of ANN). You are right, you only need one matrix of weights if you have less than the maximum number of patterns for a given net. The Hebbian rule is quite trivial to implement …

Member Avatar for lotrsimp12345
0
499
Member Avatar for xikkub

With GLUT you cannot enforce a fixed time-step or frame rate because GLUT controls (partially) when the frames get rendered. I assume you have a rendering function which performs all the calculation for one frame and renders it. I assume also that your animation is stepping forward in "virtual time" …

Member Avatar for xikkub
0
312
Member Avatar for acv528k

1) The reason why it doesn't run on your compiler but runs on the prof's compiler (or test thing) is that the value of "num" is not initialized. At line 7, it creates an int called "num" with no initial value, so the value of num could be anything when …

Member Avatar for Fbody
0
131
Member Avatar for PieterA

If you pay attention to this sentence: >>These last four classes are all expanded to have a graphical implementation with SDL. You see that the last four classes should be expanded to include some display function (and maybe others). This calls for multiple inheritance. You can make another base class …

Member Avatar for PieterA
0
247
Member Avatar for hystaspes

Guarding the header is enough, it guarantees that the header's definitions only appear once. So having a guard inside a guard is useless (not incorrect per se, but useless). You have to soften your coding standards. Most rules are not that strict, as Sutter and Alexandrescu already point out in …

Member Avatar for hystaspes
0
979
Member Avatar for simul8or

The ellipsis is an oddity of C++. As said by sean, it can be used for having a variable number of parameters to a function (called variadic parameters). Also, it can be used (as in the try catch example above) to accept any parameter (as in catching any and all …

Member Avatar for mike_2000_17
0
121
Member Avatar for lasl0w

If you have no restriction as to what you are allowed to use, I highly recommend you use the class "[URL="http://www.cplusplus.com/reference/stl/set/"]set[/URL]" (#include <set>) to store the records. In order to use it, you will need to overload the less-than operator (<) in whichever way you like to sort the elements. …

Member Avatar for mike_2000_17
0
199
Member Avatar for claudiordgz

It seems alright to me as far as the procedure you have taken to export the class from the DLL. That is the way to do it, as far as I know, but I don't do it often because of the remarks that follow. One important thing that always needs …

Member Avatar for claudiordgz
0
146
Member Avatar for MasterGberry

The problem is that you have default values for both parameters of your parametrized constructor. This means that this parametrized constructor can be called without any parameters, just like the default constructor. This is where the ambiguity comes from, if you create an object without parameters to the constructor, should …

Member Avatar for MasterGberry
0
148
Member Avatar for tech9x

You are only resizing the "test" array, you also need to resize the "command" array (or use command as a temporary string since you don't really need to keep a record of it anyways). If you want an easier solution, I highly recommend you use [URL="http://www.cplusplus.com/reference/stl/vector/"]std::vector[/URL] (#include <vector>).

Member Avatar for mike_2000_17
0
130
Member Avatar for badllama

You can also use template specialization with a template... you can avoid the ordering problem of the default template argument. What I mean is this: [CODE] //create a placeholder struct for key types template <class T> struct key { }; //create a placeholder struct for data types template <class T> …

Member Avatar for badllama
0
140
Member Avatar for tech9x

You have a whole bunch of uninitialized pointers at line 7: [CODE] int *day, *month, *hour, *min, *_hour, *_min; [/CODE] Since you send those pointers by value to the function calls that you have, the only way that this program will not crash is if you don't use those parameters …

Member Avatar for mike_2000_17
0
138
Member Avatar for claudiordgz

I'm assuming you have access to the source code of the DLL, otherwise you would not be attempting to use class methods that are exported from it (there are reasons why this would be impossible). I don't know where you got your info, but the methods you tested are all …

Member Avatar for claudiordgz
0
257
Member Avatar for vbx_wx

It should work, verify that pthread_create actually returns 0. As in [URL="http://programmingexamples.net/index.php?title=CPP/PThreads"]this example[/URL]. Check out Boost.Thread library, it is about to become the C++ standard library for multi-threading because it is easy and effective (and cross-platform), I strongly recommend it. See examples on [URL="http://programmingexamples.net/index.php?title=CPP/Boost/Threads"]using Boost.Thread with a global function[/URL] and …

Member Avatar for mike_2000_17
0
86
Member Avatar for vavazoom

If you are not obliged to use pthreads, I would highly recommend using [URL="http://www.boost.org/doc/libs/1_44_0/doc/html/thread.html"]Boost.Thread[/URL] instead. Both because it is so easy and it is about to be the standard multi-threading library for C++0x. As for your problem, it is quite a classic and important scenario in multi-threaded applications. The term …

Member Avatar for mike_2000_17
0
281
Member Avatar for archduke83

Line 78, you messed up the operation priority. It should be: [CODE] z[m] = z[m] + (2/(lambda*alpha))*diffX[m]; [/CODE] To match the matlab version. BTW, if you plan to use this C++ implementation, you have some serious cleaning up to do. You have way too much temporary memory allocations and passing …

Member Avatar for archduke83
0
258
Member Avatar for vbx_wx

I can give a few comments that might be useful.. 1. I think you have taken too much of an "externalizing" approach. What I mean is that these functions like connect, accept, and listen are kind of trivial in themselves and require the user of your socket class to do …

Member Avatar for vbx_wx
0
130
Member Avatar for lochnessmonster

Roughly speaking, you could say there are three types of classes. Those whose objects are: 1- Always in a valid state (and always constructed successfully) 2- Completely useless if not in a valid state 3- Could be in an invalid state and still be useful (or recoverable) 1- A trivial …

Member Avatar for mike_2000_17
0
129
Member Avatar for Weird Nerd

That's very easy actually. In order of simplicity: 1. You can use the function [URL="http://www.opengl.org/sdk/docs/man/xhtml/glFrustum.xml"]glFrustum()[/URL] which takes left, right, bottom, top, near and far coordinates for the projection, all centered about the vanishing point. So if top and bottom are not equal in magnitude (like 1 and -1) then the …

Member Avatar for Weird Nerd
0
515
Member Avatar for mike_2000_17

Hey y'all, I was just curious about which idiom you prefer or use very often.. and why? Please vote on the poll! I understand that there are a lot of choices but you can vote for multiples, but try to pick only the ones you think are the best, or …

Member Avatar for mrnutty
0
212
Member Avatar for aaronmk2

To elaborate a bit more. Your data member "empID" will have its destructor implicitly called when your object of class "heap" gets destroyed. And since std::vector will release all its memory in its destructor, there is nothing you need to do in your destructor (it is all done implicitly, that's …

Member Avatar for arkoenig
0
108
Member Avatar for lochnessmonster

I'm only going to show you how to implement the processHandle in RAII, the others are for you to do in a similar fashion. You simply wrap the processHandle in a private struct (if you don't need to reuse this struct's code somewhere else in your library). Then, you load …

Member Avatar for mike_2000_17
0
287
Member Avatar for alaa sam

If you ran out of stack memory, that is probably with your recursive implementation. The rule is that if you write a recursive function for which you expect very deep recursion (like 500 recursive calls), then you should really minimize the number of local variables in the recursive function definition. …

Member Avatar for alaa sam
0
106
Member Avatar for lochnessmonster

So far, I think all the above answers are very good and have all the essential ideas. One additional guideline I can think of is about preserving interfaces (but probably doesn't concern you too much at this point, it's more for bigger projects). There are programming techniques such as some …

Member Avatar for mike_2000_17
0
311
Member Avatar for bkempert

I can see a few problems: 1. You don't delete the nodes that you pop, that is a memory leak. 2. I don't see a default constructor that sets the initial value of "tos" to NULL, if that is not done, it will surely lead to a segmentation fault if …

Member Avatar for bkempert
0
135
Member Avatar for shanker86

The important lines would be something like this: [CODE] cmake_minimum_required (VERSION 2.6) add_executable(demo "x04.cc") find_library(PLPLOT_LIB NAMES plplotcxxd PATHS "/usr/lib/") #or some other path if(NOT PLPLOT) message(FATAL_ERROR "PlPlot library is missing") endif() target_link_library(demo ${PLPLOT}) [/CODE] Note that you should probably follow a [URL="http://www.cmake.org/cmake/help/cmake_tutorial.html"]cmake tutorial[/URL] because there are many more things you …

Member Avatar for shanker86
0
172
Member Avatar for spetro3387

***PLEASE USE CODE TAGS IN THE FUTURE*** Your problem is classic. You should know that the pthread_cond_wait function is subject to spurious wake-ups. This means that sometimes (fairly often actually), the pthread_cond_wait function will return even when the condition was not signaled. You need to use a predicate. This means, …

Member Avatar for spetro3387
0
229
Member Avatar for mrnutty

Well I'm certainly curious to see if a linear time algorithm exists, can't think of any. As a starter, I can think of a few basic methods: - Brute force: pick each element of A and do a linear search for its match in B. If a match is found, …

Member Avatar for arkoenig
0
102
Member Avatar for SVSU_Student

Welcome! I also hope you have solved the problem already, but it won't be from the help of the previous answers (sorry guys). What you need to do is loop until you hit the end of the file. The end-of-file is found by simply using "inputFile.eof()". It returns true if …

Member Avatar for Frederick2
0
375
Member Avatar for tKc

First, the prototype for selectionSort should match the definition EXACTLY, always. So, this will rectify it: [CODE] void selectionSort(int a[], int size); //and you should place it outside and before main() [/CODE] The reason why the compiler doesn't care is because the compiler won't see a difference between two function …

Member Avatar for tKc
0
164
Member Avatar for dnambembe

**Please use code tags in the future** First, one little thing that often comes up, your GetNumber function should include a "cin.ignore();" call to clean the input buffer after entering a numeric value of any kind. So it should be: [CODE] void GetNumber( ) { cin >> reco.Dlicense; cin.ignore(); } …

Member Avatar for dnambembe
0
1K
Member Avatar for Obsidian_496

Don't give up. It is easy to do this as long as you stay away from Microsoft products (you are experiencing their tactics of giving away the Express version to sucker people into buying the full version.. just like a pill-pusher). You said you have Borland... is this Borland C++Builder …

Member Avatar for mike_2000_17
0
709
Member Avatar for whaba

The problem is that you are updating the screen only when an event comes. So if you move the mouse, you trigger a bunch of unhandled mouse_move events that also makes your screen get updated. You should move the group of lines that perform the move, applysurface, show, and SDL_flip, …

Member Avatar for mike_2000_17
0
121
Member Avatar for oggiemc

I see no syntax problem with this code.. have you tried compiling it? The only problem is that you are using friendship relation for a pretty trivial purpose. What is wrong with a simple getHeight() member function in both classes, or better yet as a virtual method in the Dog …

Member Avatar for mike_2000_17
0
159
Member Avatar for lauruskamj

At line 35, you need parentheses to enclose "denominator1*denominator2" like you did at like 42. As for the main problem, lines 53 to 56 are very wrong. There is absolutely no relationship between sum_result in main() and sum_result in add_fractions(). These are two completely unrelated variables. The fact that they …

Member Avatar for mike_2000_17
0
99
Member Avatar for malayasthana

Aside from what AD proposed, there are all the modifiers in the [URL="http://www.cplusplus.com/reference/stl/vector/"]std::vector[/URL] class: - [URL="http://www.cplusplus.com/reference/stl/vector/assign/"]assign[/URL]() : overwrite the content of the vector from either a constant or another iterator pair (begin,end). - [URL="http://www.cplusplus.com/reference/stl/vector/push_back/"]push_back[/URL]() : add an element at the end. - [URL="http://www.cplusplus.com/reference/stl/vector/pop_back/"]pop_back[/URL]() : subtract the last element. - [URL="http://www.cplusplus.com/reference/stl/vector/insert/"]insert[/URL]() …

Member Avatar for mike_2000_17
0
121
Member Avatar for merse

I remembered answering a similar post before [URL="http://www.daniweb.com/forums/thread321879.html"]here[/URL], but then I realized you (merse) were also the OP for that thread. I guess you are obsessed with this topic... If what your are looking for is top speed and perfect accuracy, you just moved beyond obsession.. into fanatical idealism. In …

Member Avatar for merse
0
237
Member Avatar for lochnessmonster

You can throw any exception to like, if you have a specific purpose that doesn't fit in the standard exceptions, then make your own: [CODE] #include <exception> class InvalidProcessException : public std::exception { private: std::wstring message; public: InvalidProcessException(const std::wstring& aProcessName,const std::wstring& aDllName) : message("Invalid Process Exception with process name '" …

Member Avatar for Milton Neal
0
80
Member Avatar for Alec0905

This is too much code for me to look at... but just a quick run through your findPath() function shows that you have no return statement after a recursive call. Normally, you would use the result of the recursive call to either return it directly or use it to compute …

Member Avatar for Alec0905
0
202
Member Avatar for cwarn23

Just abandon the CLR part. .NET and all this C# and managed C++ is useless and cumbersome. If your problem would have been just in straight C++, it would have been solved in minutes (using [URL="http://www.boost.org/doc/libs/1_44_0/doc/html/thread.html"]Boost.Thread[/URL]), but only because of marshalling stuff and the evil .NET platform, you are stuck... …

Member Avatar for Ancient Dragon
0
725
Member Avatar for Tyster

The way you set up your addition function, it will add the value of the parameter to "this" object, so you don't need the assignment at all, or you need to redefine the implementation. This line: [CODE] x = c.addition(d); [/CODE] actually adds d to c and stores the result …

Member Avatar for mike_2000_17
0
161
Member Avatar for merse

If you want to access the data member from another class or function specifically, you can use the "friend" keyword, as such: [CODE] #include <iostream> class Bar; //forward declaration class Foo { public: void someMethod(const Bar& a); }; class Bar { private: int x; public: Bar(int aX) : x(aX) { …

Member Avatar for mike_2000_17
0
141
Member Avatar for malayasthana

First, you have an excess semi-colon in the for-loop line, this will actually cause the loop to do nothing and try to dereference the end iterator (possibly a segmentation fault or access violation). The line should be: [CODE] for ( it = file_user.begin() ; it != file_user.end(); it++ ) //notice …

Member Avatar for Fbody
0
146
Member Avatar for myrk

@ffej2ffej: If you don't mind OOP and pointers, I would recommend Qt (it is easy, cross-platform, and comes with very decent, [URL="http://qt.nokia.com/products/developer-tools/"]lightweight IDEs[/URL] for windows, Mac and Linux). @OP: Just use [URL="http://www.libsdl.org/"]SDL[/URL] (Simple Directmedia Layer). It is not object-oriented at all (essentially a C library), has those good'ol' fashion handles …

Member Avatar for Stefano Mtangoo
0
709
Member Avatar for MasterGberry

You have three places (line 20, 31 and 32) where you do something like this: [CODE] contributors * thePatrons = new contributors []; [/CODE] I have no clue why your compiler allows this or into what it gets compiled.. I just know that it is wrong (or at least very …

Member Avatar for MasterGberry
0
95
Member Avatar for mdpepper

As FBody said, of course, you need to match the function declaration in the cpp file to take a Date as second parameter instead of three ints. Then, it should work. Just in case you previously changed it to three ints because you had trouble creating a patient object, here …

Member Avatar for mike_2000_17
0
166
Member Avatar for russellquin

You are right, the variable will wrap around to its highest value. The only way that I know of to avoid it is to do the following: [CODE] unsigned int num = 0; num = (num < 1 ? 0 : num - 1); cout << num; [/CODE]

Member Avatar for Duoas
0
92
Member Avatar for brandonrunyon

If you want to keep the sum function template as is, you can also use the following code which uses the conversion operator (operator int()): [CODE] #include <iostream> class Homework { int time; public: void SetTime(int t) { time = t; } explicit Homework(int t) : time(t) { }; //add …

Member Avatar for brandonrunyon
0
268

The End.