164 Posted Topics
Re: Since you are using an array to emulate a dynamically sized container, I would definitely suggest you use a string type or container type from the standard template library. This way, you can be sure that you won't overrun your array, and you don't have to allocate large storage and … | |
Re: I wrote a class that functions correctly. However, I assume this is homework, so I won't give you the solution code. I will describe a good solution to the problem for you, though. First, I don't really see a reason to use strings for your storage. You might use chars, … | |
Re: [QUOTE=wwsoft;1115840]so how can I make this accept all object types ? [code] create_object(object_type) { new object_type myobject; _objects_.push_back(myobject); return _objects_.at(_objects_.end); } [/code][/QUOTE] As long as your vector will contain homogenous types (i.e. they are all the same). You could use a templated function: [code] template<class T> T& create_object( vector<T> objects … | |
Re: Here is a working example with a few notes at the bottom: [code=c++] #include <iostream> using namespace std; enum ops{ ADD, SUB, MLT }; template <class T> class Matrix{ private: T* mat; int rows; int cols; int sz; void initMat( int rows, int cols ){ if( rows <= 0 || … | |
Re: [QUOTE=blue:;1113737] y=f/2; [COLOR="Red"]//This will tell you nothing about the evenness of f[/COLOR] if ( y= 0) [COLOR="Red"]//This will always resolve to false because the assignment operator essentially returns the rvalue, which is always 0 in this case. Perhaps you meant y==0 ?[/COLOR] cout<<"even"; else cout<<" odd"; } [/QUOTE] This is … | |
Re: [QUOTE=Skeen;1114660]So I'm working on this class, which is basically to wrap a char into 8bools, and it works so far, however I'm running into a problem, in the dedication of values, since I'm to use the overloaded array operator, as well as the overloaded assignment operator, at once, however I … | |
Re: I suggest this change. [CODE] sum += x; if (count==0){ largestnumber = x; smallestnumber = x; } else{ largestnumber = max( x, largestnumber ); smallestnumber = min( x, smallestnumber ); } [/CODE] 1. Use the += operator. It's just nice. 2 . You should you an if else statement. There's … | |
Re: [QUOTE=dardar4;1114439]yes, i know i should use cvFitline(); but as i stated i'm not sure what this function does. what does it returns? and how do i work with it?[/QUOTE] The link he provided describes everything you need. Also, this is a c++ forum, not an OpenCV forum. OpenCV has a … | |
Re: If I read this correctly, you are wanting to choose (with replacement) r items (points in this case) from a set of n items? This can be done easily using a vector to hold the sets: [code=c++] #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(int argc, char … | |
Re: [QUOTE=falcon60;1113599]Hello! I'm beginning learning C++ and I was wondering, does Visual Studio 6.0 support all of the language features or is it too outdated now? If so are there any free compilers/linkers that I can use for windows programming? I'm also worried about the windows API headers being outdated as … | |
Re: Have a look at Qt. It is an excellent GUI development kit for c++, and the basics are really easy to pick up. Qt's developers also offer a fully integrated IDE for both developing the code and designing the gui. It is called Qt Creator. There is extensive documentation available … | |
Re: You have some value index confusion happening here I think Try [code=c++] int temp; int idx0 = rand() % 16; int idx1 = idx0; while( idx1 == idx0 ) idx1 = rand() %16; temp = Dice[idx0]; Dice[idx0] = Dice[idx1]; Dice[idx1] = temp; [/code] | |
Re: I know the solution to the random reordering has already been handled, but here is a solution that I find more mathematically satisfying. 1. Assign each die a random x, y coordinate a. The coordinates should be real numbers (i.e. doubles ) b. If you prefer integers, then the range … | |
Re: You can also deduce the indices of a 2D array from a 1D iterator using modulus math: [code=c++] /* Performs both integer division and modulo with improved efficiency */ void divmod( int dividend, int divisor, int "ient, int &remainder ){ quotient = dividend / divisor; remainder = dividend - divisor … |
The End.