2,898 Posted Topics

Member Avatar for dospy

I think that [URL="http://www.boost.org/doc/libs/1_47_0/more/getting_started/windows.html#or-build-binaries-from-source"]the instructions on the boost website[/URL] are already pretty much "step by step", I don't know how I could give any more straight-forward instructions. Also note that most Boost libraries are header-only libraries, meaning that you don't actually need to build the binary libraries to use those …

Member Avatar for dospy
0
153
Member Avatar for teo236

>>how can I sleep my program without sleeping others (or making them slower)? You can't make other programs sleep... What are you talking about, what are "the others". The Sleep function is perfectly ok, it "Suspends the execution of the current thread until the time-out interval elapses." - msdn. What …

Member Avatar for teo236
0
203
Member Avatar for Mahkoe

>>I can't for the life of me figure out a way to copy the value stored in the char array into a bigint and I don't think the developers of the bigint libraries intended for them to be used that way. The developer of [URL="https://mattmccutchen.net/bigint/"]bigint[/URL] did indeed provide a function …

Member Avatar for mike_2000_17
0
257
Member Avatar for valestrom

This piece of code makes no sense: [CODE] struct NArcher { extern int enemyattack = 10; extern int enemyhealth = 20; extern int enemydefense = 5; extern char enemy = 'Nathan Archer'; } ; [/CODE] First with the obvious, if "enemy" is supposed to store a string, it should be …

Member Avatar for mike_2000_17
0
363
Member Avatar for jammmie999

A few things to check: 1) Verify that your library is correctly loaded, i.e. [ICODE]Test != NULL[/ICODE] 2) Verify that your function pointer is correctly obtained, i.e. [ICODE]Entry != NULL[/ICODE] 3) Make sure that the "PluginEntry" function (in your DLL) is declared with [ICODE]extern "C"[/ICODE] 4) Verify that your calling …

Member Avatar for jammmie999
0
787
Member Avatar for D.M.

Here's my opinion on it (compilers, not IDE or build-systems): [B]Portability[/B]: GCC (GNU Compiler Collection) [B]Compilation Speed[/B]: BCB (Borland C++ Builder) [B]Code Optimization[/B]: ICC (Intel Compiler Collection) [B]Usefulness of compilation warnings and errors[/B]: GCC [B]Debugging capabilities[/B]: MSVC 2010 (Microsoft Visual C++ 2010) [B]Strict standard compliance[/B]: Comeau and ICC (using the …

Member Avatar for pseudorandom21
0
327
Member Avatar for Labdabeta

Wow! You are stepping into a problem that is bigger than you can comprehend (no offense). This problem is the general problem of [URL="http://en.wikipedia.org/wiki/Collision_detection"]collision detection[/URL]. To do this correctly and efficiently is a huge deal. Generally, to solve this problem, you need to solve a number of very difficult problems. …

Member Avatar for Labdabeta
0
215
Member Avatar for caut_baia

Definitely GCC is the best (and only) compiler right now that has a pretty good support for C++0x (C++11) features. A quick look at [URL="http://wiki.apache.org/stdcxx/C%2B%2B0xCompilerSupport"]this table[/URL] reveals this pretty clearly. And specifically for GCC [URL="http://gcc.gnu.org/projects/cxx0x.html"]here[/URL]. From looking at the list, you can see that 4.6 is a pretty good version, …

Member Avatar for caut_baia
0
443
Member Avatar for Zssffssz

Ok, if you don't have the internet connection on the machine on which you want to install the compiler, then it is much more tedious to install software on Linux. Many linux distros come with the compiler pre-installed, and I believe Kubuntu is one of them, you can first check …

Member Avatar for limaulime
0
228
Member Avatar for anujthefuhrer

Read [URL="http://en.wikipedia.org/wiki/User_Virtual_Address_Space"]this wiki[/URL]. Basically, any pointers in a program is "logical" (or virtual), never physical (unless you are not running under an operating system). Managing the memory allocated for processes is a job for the OS (i.e. the OS manages where memory is allocated to store the executable code for …

Member Avatar for doug65536
0
846
Member Avatar for u8sand

Uhmm... saving a function to a file to be able to call it later from anywhere else... if I'm not mistaken (rethorical), this is called a [URL="http://en.wikipedia.org/wiki/Dynamic-link_library"]Dynamic Link Library[/URL] (DLL) (in Windows) or a Shared Object (SO) (in *nix). Any way you want to do what you want to do, …

Member Avatar for doug65536
0
303
Member Avatar for dospy

Why not go for the standard threads? They have just been added to C++ (with C++11), so you might as well learn to use that. The standard thread libraries are supported (at least most of it) by most compilers. It is also almost exactly the same as the Boost.Thread library …

Member Avatar for dospy
0
251
Member Avatar for markfw

You do a cast to [ICODE]unsigned int[/ICODE] and then you cast it back to [ICODE]T[/ICODE]. This kind of cast generally has undefined behavior, but it is defined that doing [ICODE](T)(U)t[/ICODE] for [ICODE]T t;[/ICODE] should yield the same value as [ICODE]t[/ICODE]. So, your code is merely checking a standard-defined behavior, if …

Member Avatar for mike_2000_17
0
202
Member Avatar for ChaseRLewis

The streams work on a streambuf object. The [URL="http://www.cplusplus.com/reference/iostream/streambuf/"]streambuf[/URL] is an abstract base class that provides a buffer interface for use by the stream objects (like ostream and istream). Two derived class are provided by the standard, the filebuf and stringbuf classes (where, obviously, the filebuf reads/writes to a file …

Member Avatar for mike_2000_17
0
110
Member Avatar for ben1996123

The error message means that your [ICODE]int energySystem::getEnergyLevel()[/ICODE] should be made a const member function in order to be called with a const energySystem object. That is, you need the following prototype: [CODE] int energySystem::getEnergyLevel() const; //notice 'const' here. [/CODE]

Member Avatar for ben1996123
0
560
Member Avatar for mike_2000_17

Hey, I have a set of types which are all arithmetic (have operators for addition, subtraction, multiplication, etc.). I want to aggregate any number of them into a single object, so I'm using the std::tuple class template and the <tuple> library (and Boost.Tuple for backward compatibility). My question is a …

Member Avatar for mike_2000_17
0
531
Member Avatar for NoUserNameHere

>>an ampersand right before the function name That's the wrong way to think about it. The ampersand is right after the return-type declaration, in other words, the ampersand is part of the definition of the return-type. In this case, the function returns a reference to an int variable. It also …

Member Avatar for mike_2000_17
0
109
Member Avatar for dospy

It is also more efficient (don't use random-access, via an index, if it is not needed). It is also more idiomatic. Also, the new C++ standard makes it a bit cleaner with the "auto" keyword, as so: [CODE] vector<int> myvec; // let's assume it's initialized for(auto it = myvec.begin( ); …

Member Avatar for dospy
0
182
Member Avatar for kutuup

Lines 54 to 61 are off by one. You should know that indices in C/C++ go from 0 to N-1, that is, for an array [ICODE]hotspot* hotspots[8];[/ICODE], the indices should go from 0 to 7, not from 1 to 8. This is really basic stuff. Your default constructor does not …

Member Avatar for kutuup
0
269
Member Avatar for dospy

Inlining functions is, first of all, something that the compiler does. So, the first rule is that the compiler has to be able to find the definition of the function (definition = function body). As Fbody said, the compiler only looks at one "translation unit" at a time (a translation …

Member Avatar for Fbody
0
2K
Member Avatar for marirs07

>>The problem is quite clear....I need to find the base address of the struct .I know that the name is Check and the address of one of the member is p And the answer is clear: [B]IT IS IMPOSSIBLE![/B]

Member Avatar for marirs07
0
3K
Member Avatar for wnr78ta

I can't really see the error, but you said that there is code that does [ICODE]typedef double T;[/ICODE]. I don't think you grasp the ramifications of doing this! This is horrible, and very dangerous. The "T" is very very often used as a name for a template parameter. If you …

Member Avatar for wnr78ta
0
337
Member Avatar for Cainer

Basically, optimization flags play a big role in increasing the performance of an application. You need to first make sure you compile under "Release" mode, which will disable debugging hooks and features (so you won't be able to stop the program with break-points and step through it). Those debugging hooks …

Member Avatar for mike_2000_17
0
148
Member Avatar for dospy

Learning to use command-line arguments is definitely part of the basic things you just need to know, even if you have other practices yourself. As for command-line vs config-file, why not use both? See the [URL="http://www.boost.org/doc/libs/1_47_0/doc/html/program_options.html"]Boost.Program-Options[/URL] library.

Member Avatar for dospy
0
2K
Member Avatar for Labdabeta

Assuming you are using GCC (which usually comes with CodeBlocks), then you need to read [URL="http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html"]these instructions[/URL]. You can also create assembly listings files (with .s extension) which contain a full compilable assembly code (in a human readable listing). Then, you can assemble the assembly listings file into an object …

Member Avatar for mike_2000_17
0
238
Member Avatar for falconmick

Maybe I missed something here, but if you have a sorted sequence of items, isn't it super easy to determine the BST order of insertion? You insert the middle item (median) first, then the median of each half and the median of each quarter and so on, so forth. But, …

Member Avatar for mike_2000_17
0
439
Member Avatar for Xide

What you are looking for is a dynamic array container, in C++, there are many containers, the most usual being [ICODE]std::vector[/ICODE], find info on it [URL="http://www.cplusplus.com/reference/stl/vector/"]here[/URL]. Here's a very simple example: [CODE] #include <iostream> #include <vector> int main() { std::vector<int> variables; int x; std::cout << "Enter a number (0 to …

Member Avatar for mrnutty
0
167
Member Avatar for meli123

Let me clear out some confusion about "bool". Strictly speaking, a bool value can be true or false, so, it can only take two values. Practically speaking, any integer value is implicitly converted to bool as if you wrote [ICODE]bool(value != 0)[/ICODE], meaning that any non-zero value is interpreted as …

Member Avatar for mrnutty
0
96
Member Avatar for t2r

>>There is a lot of tutorials but they are all without code example That's normal. There is a big difference between learning a programming language and learning software design. First, you need to get familiar with the syntax and idioms of a particular programming language. And learning to create classes …

Member Avatar for t2r
0
188
Member Avatar for Labdabeta

Most "special" math functions (like trigo., sqrt and exp/log) translate directly into a single instruction or a few (in assembly), and the performance of those instructions depends on the hardware. Of course, this is if your system has those instructions, most non-microcontrollers have them (unless your PC is more than …

Member Avatar for BCBTP
0
127
Member Avatar for cheeseboy

Your CalcNrCases() function should take the BottlesLeft parameter by reference if you intend to modify its value as an additional output of your function. As so: [CODE] //the prototype: int CalcNrCases(char, int, int&); //... //the function: int CalcNrCases(char BottleType, int NrBottles, int& BottlesLeft) { [/CODE]

Member Avatar for mike_2000_17
0
544
Member Avatar for trantran

Well, it is certainly useless to do it this way, but if you do, then yes, the compiler will optimize this away. If it doesn't, then it is a very pessimizing compiler (pessimizing = anti-optimizing). All modern compilers do this. In general, the rule of optimizations is the "as if" …

Member Avatar for trantran
0
177
Member Avatar for fsefsef23

A pure (or minimal) stack implementation would just provide a few functions: usually just one to push a new element to the top of the stack, one to read the top element of the stack, one to pop the top element off the stack, and a function to tell if …

Member Avatar for mike_2000_17
0
223
Member Avatar for coolbeanbob

You wrote "List" instead of "list", C++ is a case-sensitive language. Because the compiler does not recognize the "List" as a type (and thus starting a declaration of a parameter-list), it thinks that line 12 is a declaration (and initialization) of a "variable or field" called "start" and because it …

Member Avatar for coolbeanbob
0
468
Member Avatar for GatorProgrammer

I think that the only problem with your code is that the bound on the for-loop should be the variable "bound", not the variable "sum". You had this: [CODE] for(i = 1; c <= sum; i++) [/CODE] I think you should have this instead: [CODE] for(i = 1; c <= …

Member Avatar for mike_2000_17
0
168
Member Avatar for imcgrath1

The multimap class includes a function, called [URL="http://www.cplusplus.com/reference/stl/multimap/equal_range/"]equal_range[/URL], which returns the range (as iterator pair) of elements of the multimap that have the same key. Finding the number of elements with the same key is simply a matter of counting the elements in that range. If your purpose is to …

Member Avatar for mike_2000_17
0
3K
Member Avatar for tyu1996

>>is there only a constant C++ syntax in the world Constant, no. Standard, yes. Standards get revised over time, so it's not constant. For C++, the dates to remember are 1998, 2003, and 2011. C++98 is the first ISO standard for C++, anything pre-dating that is "pre-standard" C++ (because the …

Member Avatar for cse.avinash
0
194
Member Avatar for bennetk2

Are you in the same course as [URL="http://www.daniweb.com/software-development/cpp/threads/381859/1644783"]monkeybut[/URL]? I believe the problem is that the line 45 should be within the for-loop. I also posted a solution on the thread by monkeybut, but I wouldn't suggest submitting that for your assignment, the prof will be very suspicious if you do.

Member Avatar for bennetk2
0
2K
Member Avatar for falconmick

There is no technical issue with your code. But you have some other small issues. First, if you don't intend to return a writable variable, then you should make that member function const (if it is indeed a member function, which is what I assume). Second, returning a pointer is …

Member Avatar for falconmick
0
244
Member Avatar for valestrom

>>Sarcasm? I hope. Cause this is c++ No. It's not! C++/CLI is not C++. It's a completely different language and it's more akin to C# than anything else.

Member Avatar for valestrom
0
205
Member Avatar for DrShroom

>>The issue that i am having now is reducing the fractions after they are added/subtracted, etc. You already have a function to reduce the fraction, why not reuse it by calling it within your operator functions. As so for example: [CODE] RationalNumber RationalNumber::operator+(RationalNumber &c) { RationalNumber result; result.setFraction(((numerator * c.denominator) …

Member Avatar for DrShroom
0
284
Member Avatar for Cainer

Your operator overload defines an operator for Number + int, not for int + Number. Even though mathematically, addition is commutative, the compiler does not assume it is because you could define an addition operator that shouldn't be commutative. Anyways, to solve the problem, you should define two operators, one …

Member Avatar for gerard4143
0
235
Member Avatar for dolfan55aj

Turning a loop into a recursion is pretty simple: the body of the loop becomes the function body, and the loop-variable becomes the parameter passed from one recursion to the next. The loop you have is not the best to lead you into making it a recursion, may I suggest …

Member Avatar for mike_2000_17
0
525
Member Avatar for monkeybut

May I humbly suggest that you avoid the need to use transcendental functions (log and pow) and those nasty C-style casts by doing this: [CODE] void convert_base(int v, int b){ std::stringstream ss; do { ss << (v % b); } while( v /= b ); std::string s = ss.str(); std::copy( …

Member Avatar for mike_2000_17
1
530
Member Avatar for ntrncx

>>i did this but not sure if its what the exercise asks That looks OK to me, except that your vector should be a vector of integers if you plan to store integers. That is: [CODE] vector<int> elements; //not vector<bool> elements; [/CODE] Another idiomatic way to fill that vector is …

Member Avatar for ntrncx
0
147
Member Avatar for mullerfourie

>>a + b would be a.operator+(b) but then how can 5+b be 5.operator+(b) since 5 is a int. You're wrong. Although you can make an overloaded operator as a member function (i.e. a.operator+(b)), that's not the preferred way, normally it is implemented as a free-function. As so: [CODE] // this …

Member Avatar for mullerfourie
0
215
Member Avatar for NathanOliver

@raptr_dflo: First, thanks for your kind words. Let me give you a quote of me quoting other people: "In C++, the preferred channel for signaling exceptional situations is by throwing exceptions. This assertion will not be defended here because it has been discussed at great lengths by most pilars of …

Member Avatar for mike_2000_17
0
161
Member Avatar for Johnny666

Your deep-copying is essentially correct. But you are really complicating things by not using the std::string class instead of char-arrays. Always prefer using RAII classes when they are available. I also recommend you read my tutorial on building a [URL="http://www.daniweb.com/software-development/cpp/tutorials/373787"]RAII class[/URL]. As for your code: Line 10 is useless. Line …

Member Avatar for raptr_dflo
0
185
Member Avatar for hondros

That's very nice. It's good to remind people that binary IO does imply worrying about endian-ness. I do have a few additional caveats and improvements to suggest. 1) On C++ basics, there is no reason to use pointers in this case, passing-by-reference would be cleaner and safer. 2) Your use …

Member Avatar for mike_2000_17
0
369
Member Avatar for garu525

My eagle eye has spotted this at line 43: [CODE] else if (line [i] = top ( stack )) [/CODE] Are you sure you want a single equal sign there? I'm pretty sure you don't. If I had a dime for every time I see this, I'd be a rich …

Member Avatar for garu525
0
168

The End.