- Upvotes Received
- 10
- Posts with Upvotes
- 9
- Upvoting Members
- 6
- Downvotes Received
- 2
- Posts with Downvotes
- 2
- Downvoting Members
- 2
48 Posted Topics
Re: have a look at the boost Spirit library, there is an example where they do exactly that. basically you create a tree where operators are nodes and expressions subtrees with literals as leaves. It's a parse job of a Dyck-language basically (more or less). [url]http://www.boost.org/doc/libs/1_46_1/libs/spirit/doc/html/index.html[/url] Can't find the exact location … | |
Re: Yes it is possible. In fact the only justification for the continued existence of C++/CLI is that you can integrate standard C++. [EDIT] This is just my humble opinion. Why? If you want to use managed code then you are better off using C#, because it's syntactially simpler and spares … | |
Re: You can't have a dynamic array. If you want to do that you need to use vector or use new/delete dynamic allocation. Space for arrays is reserved at compiletime so that's why you need a constant expression there. | |
Re: [CODE] float **A = 0.0; // pointer for A [/CODE] You cannot do that. The initialisation takes a double calue (0.0) and tries to assign it to a pointer (A**) that is a type mismatch. use instead: [CODE] float **A = 0 /* or NULL, although some people frown upon … | |
Re: weeeeelll.... You are asking a bit much, coz writing a GUI depends entirely on the application and its requirement, but I will try to point you in a direction to get you started. MSVC uses "wizards" to create different kinds of projects. You must have used some already as you … | |
Re: All data in a digital computer is bits and bytes, effetively 0/1 strings. Datatypes of any sort are just interpretations of these data. Your job here is to serialise your object into a string of bytes before transmittions and recreate the object after it has been transmitted. Easiest to understand … | |
Re: Converting from Java to C++ is not just a matter of translating the syntax from 1 language to the other, but also the use of corresponding libraries. GUI libraries in C++ are not standardised and therefore there won't be a standard translation of your code. Which operating system are you … | |
Re: probably this helps: [url]http://msdn.microsoft.com/en-us/library/ms724235(v=VS.85).aspx[/url] You should however very sparingly use recursion as a means of looping. Recursion can always be replaced by iteration which is much lighter on resources and also much easier to debug. | |
Re: for a start I am very curious about your system call there. You don't need it or you don't need your outf variable. Either the one or the other is superfluous. Since you run "whoami" probably get rid of outf. Are you running your program from the commandline? If so … | |
Re: You will have to create a string comparison function or better a functor (if you have yet learned what a functor/function object is). And you have to use that for doing your comparison and not the standard string comparison. | |
Re: No. The gradient is the highest *CHANGE* in grey value. The maximum is what you want. Just initialise a variable maxval=0; then in a loop whenever you find a value > maxval then set it to the new maxval. Iterate through all greyvalues on your line. done. If however you … | |
Re: Well there are a few things in your code that are a bit off. First: the sin function is a function that is usually defined on the real number range. You define the function on integers which is probably what you want, but I still wanted to point it out. … | |
Re: How did you declare your variable temp? Since this->data and append.data have dynamic lengths your temp-variable needs to be allocated dynamically. [CODE] char * temp = new char[used+append.used]; [/CODE] Also this string then must be deleted somewhere [CODE] delete [] temp; [/CODE] also your function does not return anything, so … | |
Re: Read in from a file pairs of integer. Those N pairs represent 2D-vectors (in an XY- plane). Connect the vectors end-point of one connects to the startpoint of the next. Find the subset of size M<=N vectors that maximises the area this polygon encloses, if such a polygon exists. The … | |
Re: Your class DirectGraph has an overloaded [] operarator, but your variable directedGraph is a [B]pointer[/B] to a DirectGraph object. Your call should look something like: [CODE] (*directedGraph)[numSource]->adj.push_front(word); [/CODE] BTW: I see no good reason why you use a dynamically allocated object, but it's difficult to judge from the piece of … | |
Re: How do you decide that a certain restriction is needed and another is not? It's not obvious from the query and that makes it difficult for any compiler do decide what can be optimised away and what not. Optimisations of queries are best done within the database. Most major DB … | |
Re: C++ already provides you with the means to do that. [url]http://www.cppreference.com/wiki/io/io_flags?s[/url][]=hex | |
Re: Well first you need to be clear what you mean by "mean". The mean is like the average value of a number of values. In the easiest case that would be a simple vector of double values. One type of mean is the sum of all of those values divided … | |
Re: Microsoft has not the best record on backwards compatibility, but you should be able to compile an older project with a newer compiler without too much problem. Depending on the version of Visual Studio you should have a migration wizard. You should use that to migrate your project file to … | |
Re: I haven't looked too deeply into your code but at first glance there are a few things that are dangerous/undefined and wrong with your code. For a start: pointers in C++ (and C for that matter) are [B]not[/B] automatically set to NULL (0) when they are declared. They have an … | |
Re: For a start: it is no problem to create a vector of vectors which saves you naming each vector and instead use an index [CODE] typedef vector<vector<double> > DOUB_VEC_VEC; DOUB_VEC_VEC myVecs; myVecs.resize(3); // three vectors of doubles myVev[0].push_back(2.4); myVev[0].push_back(3.13); myVev[1].push_back(5.0); myVev[4].push_back(42.0); cout << myVec[0][1] << endl; // displays 3.13 [/CODE] … | |
Re: look at [url]www.boost.org/doc[/url] there are already good smart-pointers with ref counting. No need to do the work yourself ;-) | |
Re: there are different scenarios for different purposes: [CODE] void f1(int i); // call by value void f2(int* i); // pointer void f3(int& i); // call by ref void f4(int** i); // pointer to a pointer void f5(int*& i); // pointer passed by ref void f6(const int i); // call by … | |
Re: The main class object will be the last that is destroyed. That is not your problem. Your problem is that you did not create copy constructors and assignment operators. Whenever you have pointer-members in a class you should create default- and copy constructors, assignment and destructors. Your function [CODE]SecClass :: … | |
Re: use the boost function boost::posix_time::ptime after = boost::posix_time::microsec_clock::local_time(); | |
Re: if I understand properly you want to decrease the subtrahend by 3 every time and subtract it from your current result. To do that add another variable called subtrahend and initialise by 25. Each round of the loop decrease the subtrahend after you subtracted it from i. [CODE] #include<iostream> using … | |
Re: Can you describe the problem you got? I think you have a serious problem, if I understand your code correctly. I haven't compiled or run it, but your nested class node will cause grief and bodily harm, I believe. A struct is exactly the same as a class in C++ … | |
Re: The Sutter book is Excellent, Also you should look at his STL book (Exceptional STL, I think). The STL is the "way-to-do-things" nowadays and the earlier you get to grips with that the better. User-interfaces are not standardised so you need a platform specific book. Windows and POSIX - based … | |
Re: Not sure you copied all the code but if your comment is all that is in the if else block then you got a syntax error: should be like [code] void menu(void) { char a; cout<<"(E/e) Encryption"<<endl; cout<<"(D/d) Decryption"<<endl; cout<< "(Q/q) Quit"<<endl; cout<<"Enter operation code :"; cin>>a; if ( a!='e' … | |
Re: The first error comes from you having SavedClass as a parameter of [code] void LoadState(SavedClass &Save, long SavedLength, bool type); [/code] You might be able to get rid of this error by forward declaring class SavedClass. Add: [code] class SavedClass; [/code] before the definition of class InputClass and this error … | |
Re: try the following: [code] std::map<string,int> dateValueMap; for(int i=0; i<arraysize; i++) { dateValueMap[array2[x][0]] += atoi(array2[x][1].c_str()); } // output sorted by date (lexicographically) for(std::map<string,int>::iterator mapIt = dateValueMap.begin(); mapIt != dateValueMap.end(); mapIt++) { cout << "date=" << mapIt->first << " value=" << mapIt->second << endl; } [/code] I haven't debugged it and so … | |
Re: Well you are making a novice mistake her - not to worry - we all did. You should not overload the binary operators like +,-,==, and so on as [B]members[/B], but as [B]globals[/B] and make the global operators friends of the class if neccessary. The reason for this is that … | |
Re: What is the response you are getting? I had a similar problem - I did not get a bad response - in fact the response string was telling me that I was connected. Turned out that the web-site I connected to used a cookie to maintain the session state. The … | |
Re: right, there are some fundamental problems here: [code] int main(int argc, char *argv[]) { int *i; // pointer un-initialised - some random value in here // because i points to a random memory address the de-referencing will most likely // cause an unhandled exception on the print-out // if you're … | |
Re: In a way that's the only way to read from disk. If you are interested in how to do file I/O manually then I suggest you get familiar with the C++ functions fput, fget, fseek, etc. If you are asking whether sth like double* pDbl can be made to point … | |
Re: Well RAII stands for Resource Acquisition is Initialisation. And Yes you are are right in a way: The idea is to create the object that handles your resource and let its constructor handle the acquisition and the destructor handle the freeing of it. As you know all objects that are … | |
Re: you have to write your own operator for class Inputoutput: [code] ostream& operator << (ostream& os, const Inputoutput& io) { // here you have to implement how you want to output os << io.someMember << "," << io.anotherMember(); return os; } [/code] you might need to declare the new (global!) … | |
Re: You can do exactly the same in C++: in test.h [code] class Test { public: static int myArray[10]; } [/code] in test.cpp [code] int Test::myArray[10] = {0}; // the = {0} is not neccessary, but good practice as it initialises the array with zeros [/code] You declare the array in … | |
Re: what is the definition of itk::RescaleIntensityImageFilter<typename T, typename T> ? Are you sure you can pass two parameters of the same type to this template? | |
Re: You're taking avery "last-century-C-like" approach here. Although it is good to know about malloc alloc, arrays and stuff the STL is a much better choice in most cases. since you already use the STL for your streams, you should also use vectors/maps/lists etc. Get used to them they'll save you … | |
Re: Hi, you have to take your function definitions outside the main body. It looks a bit like java what you've done here. Inside the main loop you should *CALL* the functions you defined outside. [code] void greeting() { printf("\nThis Program will sort and seperate a list into primes.\n"); printf("You may … | |
Re: There are a few ways you can do that, obviously. First I'd examine the possibilty of restricting the size you need. questions to ask yourself: do I really need a full matrix? matrices can be sparse, diagonal, symmetric,.... if so: try to use specialised containers from e.g. boost ([url]www.boost.org[/url]) If … | |
Re: What kind of analysis do you want? You know that you will need 3 loops for arbitrary matrices (unless you use the fast algorithm, which saves on the loops in favour of caching some values and re-ordering the calculations). If you have constant matrix-dimensions then you can hardcode away the … | |
Re: This is a prime example of "write-only-code" and whoever wrote it should be shot on the spot. I executed the code on VS2010 and wrote an if-cascade that does the same (on this compiler) [code] i=-1; j=0; k=0; l=2; m=0; if(i&&j) { if(j&&k) { m=1; } k++; } i++; j++; … | |
Re: [code] #include <time.h> // for time(NULL) #include <vector> #include <iostream> #include <algorithm> using namespace std; srand(time(NULL)); // seed the random number generator vector<bool> field; field.resize(400); // == 20 x 20 for(int i=0;i<5; i++) field[i] = true; // the rest are all false already random_shuffle(field.begin(),field.end()); // now the 5 x-s (true) … |
The End.