2,898 Posted Topics

Member Avatar for Beancounter5

very simple: [CODE] int last_time_ms = some_time_function(); for(int year=0;year<MAX_YEAR;++year) { //perform your task.. int current_time_ms = some_time_function(); sleep(2000 - (current_time_ms - last_time_ms)); last_time_ms = some_time_function(); }; [/CODE] that's it. If you are looking for a good time function, I would suggest Boost Date-Time library, which would turn into: [CODE] #include …

Member Avatar for mike_2000_17
0
104
Member Avatar for sahil1991

I think this issue is best illustrated by a simple example. Consider the following simple program: [CODE] const int four_factorial = 24; int some_function(int* c, int* d) { return c[0]*d[0] + c[1]*d[1] + four_factorial; }; int main() { int* a = new int[2]; int b[2]; int result = some_function(a,b); delete[] …

Member Avatar for mike_2000_17
0
156
Member Avatar for Garrett2011

Consider this simple example: [CODE] double twice(double d) { return 2.0*d; }; int main() { double result = twice(2.0); std::cout << "result is: " << result << std::endl; return 0; }; [/CODE] This would, most probably, with no optimization and no inlining, to something like this in pseudo-assembly code (I'm …

Member Avatar for TechnoCat
0
138
Member Avatar for simple dude

Your question(s) is very broad. But I think that basically you are on the right path (at least in my opinion). Learning to be a skilled programmer does involve a lot of bits and pieces that you get acquainted to along the way. You said you already learned to work …

Member Avatar for simple dude
0
136
Member Avatar for Beancounter5

make sure that the method "printSummary()" is also defined as const, like this: [CODE] class MutantType { //stuff here... public: void printSummary() const { //notice the const after the function prototype. //..print stuff but cannot change any data member value. }; }; [/CODE] otherwise, the compiler will throw an error …

Member Avatar for mike_2000_17
0
93
Member Avatar for diagramatic

In my opinion, there are things that are important, others not so much. What I can think of, off the bat: Important stuff includes: - have clear names for classes and variables (identifiers), even if it makes them longer (IDE code-completion solves the extra typing issue, and it doesn't work …

Member Avatar for mike_2000_17
0
186
Member Avatar for onako

Well, think by representing the operation for small 2x2 and 3x3 matrices, you can see the pattern emerge: [CODE] //say vector<double> q is some 2x2 matrix then qt = {q[0],q[2],q[1],q[3]}; //say vector<double> q is some 3x3 matrix then qt = {q[0],q[3],q[6],q[1],q[4],q[7],q[2],q[5],q[8]}; [/CODE] For a (faster) limited-memory way, well there is …

Member Avatar for princess cesxo
0
161
Member Avatar for MyrtleTurtle

I think you would have better luck in a forum dedicated to Boost and/or Regex questions. One thing I can suggest is that the Boost Regex has to be linked to its binaries too (boost_regex.lib or libboost_regex.so/a), so make sure that is set up correctly (if not you should get …

Member Avatar for mike_2000_17
0
370
Member Avatar for maharjun

Ok.. here's the deal. When you hold a pointer within an object you need to clarify "who" owns the pointed-to memory. If the object owns the pointed-to memory, then you have to perform a deep-copy of the object if you assign it to another one and in this case there …

Member Avatar for mike_2000_17
0
1K
Member Avatar for peterman.k

First part: for the pow() function issue. I would suggest you just avoid it altogether by a simple multiplying accumulator: [CODE] int Poly::evaluate(int x) { int total = 0; int x_pow_term = 1; for(int i = 0; i <= degree; i++){ total += coefs[i]*x_pow_term; //coefs[] array is the array in …

Member Avatar for peterman.k
0
289
Member Avatar for TheWolverine

This is an issue that comes up once in a while on this forum and others. The first option that you can consider is the one that you are already trying to implement and with the link in evstevemd's post, it shouldn't be a problem to fix the syntax. However, …

Member Avatar for Stefano Mtangoo
0
4K
Member Avatar for Suzie999

I'm not a security expert either, but here is a thought to add to the options already given. Write a little program that generates a module definition file (.def) for your dll with all the aliases (symbols) of the functions encrypted, so a user app won't be able to load …

Member Avatar for Stefano Mtangoo
0
2K
Member Avatar for kchyn

you only need to call srand(time(0)) once during the application's execution. So the function you have is not dependent on time and you can generate your random numbers as fast as you like (just take the srand() call out of your function and call it once at the start of …

Member Avatar for Valaraukar
0
249
Member Avatar for neoraghav

You are missing one star at line 4 of the second code snippet: [CODE] temp2=(char***)malloc (FIRST_DIMENSION * sizeof(char *[COLOR="red"]*[/COLOR])); [/CODE] For the rest, it is the correct way to do it. BTW sizeof(char) is always equal to 1, by definition from the standard.

Member Avatar for mike_2000_17
0
2K
Member Avatar for aviavyne

From the link you gave, first, these are recursion formulas, meaning that they are calculated as the data comes in, so all those calculations should be within that value-entering loop you have (or you can loop through the data in another function and apply the formulas). Since there aren't that …

Member Avatar for mike_2000_17
0
295
Member Avatar for 4824hbk

The compiler has to know that a function called "overDraft" exists before it gets to a line that calls that function. There are two options: 1) you can declare that the function exists by putting a "prototype" of the function before "withdraw". The prototype for overDraft has to exactly match …

Member Avatar for mike_2000_17
0
100
Member Avatar for Rikard

I'm sorry to say this, but there is something awfully wrong with your implementation. If you cast a pointer to CMap to a char pointer and save, in binary, sizeof(CMap) bytes, you will also save other "undesirable" things, especially the virtual table pointer (vptr) which is not going to be …

Member Avatar for Rikard
0
214
Member Avatar for glenak

>>Also, when writing in java, especially in eclipse, you have a project folder, a source folder, a package and then the class files. Is there a similar setup I can follow with C++? When you get into C++, you enter the land of the Free. One beautiful thing with C++ …

Member Avatar for glenak
0
233
Member Avatar for YingKang

Instructions to get the above to compile: 1) add #include <string> at the start of the Product.h file. 2) replace each use of type string with std::string in the Product.h file. 3) add "using namespace std;" just after the includes in the Product.cpp file 4) as said by firstPerson, include …

Member Avatar for mike_2000_17
0
749
Member Avatar for NewLegend

Well, just uncomment the line 153 you have and it should work. Doesn't it? I would say that you need to implement a deep copy-constructor for class student_Univ, but, since your management of memory, pointers, and ownership is essentially non-existent in your code (which is very bad, especially when working …

Member Avatar for mike_2000_17
0
93
Member Avatar for danalovesc

I have to say that I disapprove greatly of this code you posted. I cannot sanction the idea of getting a pointer to a pair that is used in a map or multimap object. This is because you don't know, and I don't know, how multimap implements it list of …

Member Avatar for mike_2000_17
0
1K
Member Avatar for ThrasherK

I don't see anything wrong with your implementation except for this trivial piece missing in the main() to see the result: [CODE] vector<string> result = split(expression); cout << expression << " split into individual entities yields: "; for(vector<string>::iterator it = result.begin(); it != result.end(); ++it) cout << "'" << (*it) …

Member Avatar for ThrasherK
0
413
Member Avatar for cogitoergosum18

You store the values if you need them later, you don't if you don't need them later. For the sum itself, you will only need a temporary variable to save the input but not a permanent array. To store all of them in a "single variable", that variable will have …

Member Avatar for mrnutty
0
204
Member Avatar for emilyhedgecock

This is a classic problem that comes up almost every day on this forum. The reason for this problem is that when you do a getline, it will get the string up to the first newline (enter stroke) and will delete that newline from the input buffer. But, when you …

Member Avatar for emilyhedgecock
0
460
Member Avatar for bmos31

On a technical side, you have a problem with pointers / references / objects. A pointer is an address to an object of a class. An object is allocated for and created with new and destroyed and deallocated with delete via a pointer to that object (not a dereferenced pointer). …

Member Avatar for bmos31
0
205
Member Avatar for harpay

Well, I will do a little leap of faith and trust that you actually put some effort into it. Here is a very simple example that contains all that you need to do those two problems: [CODE] #include <iostream> using namespace std; int main() { double width = 0; double …

Member Avatar for harpay
0
452
Member Avatar for durpderp

This line: [CODE]foo * var[5];[/CODE] creates five pointers to a foo object, but that does not create five foo objects. var will hold 5 pointers to no-where or anywhere, which is the same. To initialize five foo objects for those pointers to point to, you need to do this: [CODE] …

Member Avatar for durpderp
0
109
Member Avatar for Empireryan

Line 15: the bound on the loop is wrong.. simple typo, you wrote i where it should be j: [CODE] for (j = 0; i < EVEN; j++) //should be: for (j = 0; j < EVEN; j++) [/CODE]

Member Avatar for Empireryan
0
189
Member Avatar for kerp

I think the best way to look at this problem is by dividing the tasks properly. I think your Othello class seems to be ill-defined, as you said it does "almost everything" that's a bad sign that you can't even clearly say what it does or what it is responsible …

Member Avatar for kerp
0
1K
Member Avatar for Peter_morley

Now, the problem is the difference between an object and a pointer to an object. Think of a class as any other type (like int or float or double), if you declare a variable with * it's a pointer to an object, if you declare with & it's a reference …

Member Avatar for Peter_morley
0
115
Member Avatar for Peter_morley

Ok... the problem here is that you are confusing the idea of a class and an object. A class is a type that you define. In a class, you declare what data an object of that class holds and what functions (methods) can be used on that data. The object …

Member Avatar for Peter_morley
0
455
Member Avatar for iw2z

What you have here is what is called "circular referencing" meaning that first.cpp needs what is in second.cpp to be defined and second.cpp needs what is in first.cpp to be defined (so what comes first, the egg or the chicken?). Luckily, C++ has a mechanism built-in for that exact purpose, …

Member Avatar for mike_2000_17
0
264
Member Avatar for liran ritkop

There are many more options available than the two you mentioned, but without details on what you are exactly trying to achieve, it's hard to tailor the answer. I don't know Qt at all, but I have done quite a bit of GUI, so let me give a few "generic" …

Member Avatar for mike_2000_17
0
128
Member Avatar for MarounMaroun

>>how can I do it without pointers? Like this: [CODE] class Agent { private: struct AgentStruct { std::string agentName; double pID; double mID; AgentStruct *nextAgent; } AgentP; //notice no * star sign. public: Agent(std::string); void SetNextAgent(const AgentStruct&); //notice pass-by-reference Agent* GetNextAgent(); void SendMessage(); void ReceiveMessage(); }; //... /* * The …

Member Avatar for mike_2000_17
0
174
Member Avatar for Stefano Mtangoo

What has been said so far is all true. As Milton hinted to, what I would say is the main difference between struct and class is in the traditional use of them (or programmer conventions). Most programmers and most code that I have ever seen make use of struct almost …

Member Avatar for LordNemrod
0
102
Member Avatar for sadaka

Just move this line 160: [CODE] LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);//the real winproc [/CODE] To the start of the code (after the includes) and all will be fine. The compiler has to know that there is a function (defined later) that is called WinProc and has the given prototype, before it gets …

Member Avatar for sadaka
0
112
Member Avatar for afg for life
Member Avatar for headedtomexico

The reason for this problem is that array indexes in C/C++ start at 0 and end at N-1 (not N). So One[31] is not part of the array "long One[31];" it is actually one long beyond the last element of the array. The last element of the array is actually …

Member Avatar for headedtomexico
0
126
Member Avatar for gsfare

I'm not an expert with this, but I have one idea / suggestion. This value of 4254684 looks a lot like a pointer value (converted to integer). Is it possible that you have a binary compatibility problem? Did you make sure that the static library in which the Array class …

Member Avatar for gsfare
0
158
Member Avatar for aikiart

If I may suggest another solution that you might find more elegant and that could serve other purposes for this class or another: [CODE] class MyTime { ... public: //create formatting containers: class MilitaryTime { const MyTime& obj; public: explicit MilitaryTime(const MyTtime& aObj) : obj(aObj) { }; //implement ostream overload …

Member Avatar for aikiart
0
113
Member Avatar for TGeorge824

You have to link the proper libraries for any OpenGL application. Your prof should have given instructions on how to compile. I'm not sure, it has been a while, but I think you need to link with: for Linux: libglut.a (add -lglut to the command line) and libopengl.a (-lopengl) for …

Member Avatar for mike_2000_17
0
260
Member Avatar for PixelExchange

The idea with the WinProc function is that the first parameter "hwnd" is the handle of the window whose message belongs to. So what you need to do is have a simple conditional inside the WinProc to redirect the message handling depending if the hwnd is for the first or …

Member Avatar for PixelExchange
0
317
Member Avatar for VBNick

First, a critical section is not really the synchro you need for this, you want to use a mutex (may I recommend from [URL="http://www.boost.org/doc/libs/1_43_0/doc/html/thread.html"]Boost Thread[/URL]). Second, you say you have a _list_ of structs. Is that a loose terminology or is it an actual std::list. If it is a std::list …

Member Avatar for mike_2000_17
0
187
Member Avatar for sadaka

Well this is not the first time on this forum that people have posted weird problems while using Windows Vista / 7 and Dev-C++ (a combination that has many known issues). I recommend you try another IDE, like Code::Blocks and see if the problem persists.

Member Avatar for sadaka
0
155
Member Avatar for CPT

When I look at this code, I remember why people don't program in C so much any more... This post probably belongs in the C programming forum instead. Anyhow, there is one definite problematic line, that is line 28. I found it, because that's always the first thing I look …

Member Avatar for CPT
0
153
Member Avatar for dorien

wow, I think you have a couple of concepts mixed-up here. Hexadecimal numbers are just a notation for numbers in base 16 (like decimal is in base 10, binary in base 2, and octal in base 8). The computer stores only binary data, so any value is represented in binary. …

Member Avatar for dorien
0
4K
Member Avatar for Arthas

POSIX is essentially for Linux or Unix systems. POSIX is just a specification for the API that the OS needs to expose and Linux, Unix and many others comply to those specifications. Windows does not, so windows has its own things, for example, via its Win32 API. Boost Thread library …

Member Avatar for Arthas
0
167
Member Avatar for Valaraukar

I usually tackle these problems by looking at the boundaries. In your case, you have the basic scaling factor is "energy / max" which is at most 1 and at least 0. So in any logarithmic scale (I would assume you want base 10, but that doesn't really matter), these …

Member Avatar for Valaraukar
0
180
Member Avatar for group256

At line 65, 66, and 67, you should have (index) instead of (index - 1). In the case you have index == 0, that would result in -1 and delete the element before the first one, which should result in the error you have got.

Member Avatar for mike_2000_17
0
119
Member Avatar for silvertooth07

First of all, after entering a single character, you usually want to call the ignore() function on cin to ignore the rest of the characters in the interval ]first character .. new-line (or enter)] (note the exclusive and inclusive brackets). Now, if you want a single character input in the …

Member Avatar for mike_2000_17
0
183

The End.