2,898 Posted Topics
Re: Usually, I don't like template template parameters, because of the weirdness associated with them (both in implementing the class template that receives the parameter as well as in using it). I usually prefer to go the route of meta-factory types instead. Consider this meta-factory: [CODE] template <typename FactoryTag, typename T, … | |
Re: Why not use a functor with a template call-operator. That's the way I usually take care of this kind of problem. You can also use overloading rules (and even Sfinae) if you want different implementations for different pairs of types. Here is what I mean: [CODE] struct difference_set { template … | |
Re: >>My question is, can I use this DLL now without recompiling my C code to incorporate the DEF file? Yes, as far as I know, it shouldn't be a problem. (btw, I know that I am contradicting vijayan121 on this, he may be right, but I think not, I think … | |
Re: Just replace the lines 21 and 22 with these two lines: [CODE] while(true) { cin >> Option; [/CODE] The rest can remain the same, for now. | |
Re: >>What is cout? It's a variable, yet it can print stuff on the screen. [ICODE]std::cout[/ICODE] is an object of the class [ICODE]std::ostream[/ICODE] (or a class derived from [ICODE]std::ostream[/ICODE]). It has an internal connection to the terminal output (or DOS output), which is the same as the C alternative [ICODE]stdout[/ICODE]. Most … | |
Re: On most distros you should be able to just use the "alarm" character (0x07, or "\a" as an escaped sequence). In other words, this should work: [CODE] #include <iostream> int main() { std::cout << "\a"; return 0; }; [/CODE] If not, you can use the "beep" program (install it with … | |
Re: >> Is it really hard to find someone who know how to make a good use of stl I would say that people who can't make good use of STL are not really "hire-material" for any kind of job where C++ programming skill is a key asset. Using the STL, … | |
Re: I'm not a great expert in business concerns in software developments, so take my opinion for what it is worth. It does seem that your company has been camping itself strongly on the side of "lets get the software done asap", as opposed to "lets build a robust and sustainable … | |
Re: The problem is that you don't initialize your pointers to point to anything. You have to do the same as you do for (pCDROM1, pCDROM2, pCDROM3) pointers but for each pCDs[i] element. As in: [CODE] for (int i = 0; i < 3; i++) { pCDs[i] = new CDROM; if … ![]() | |
Re: Your prototypes for operator overloads do not match. In your declaration, you have: [CODE] SavingsAccount& operator+=(const SavingsAccount& ); [/CODE] In your definition, you have: [CODE] SavingsAccount& SavingsAccount::operator+=(const SavingsAccount& double increase); [/CODE] Which is not correct syntax by the way. Either the type is 'double' or it is 'const SavingsAccount&', you … | |
Re: Like Fbody said. Line 8 should be: [CODE] node<T>* link; [/CODE] Line 16 should be: [CODE] node<T>* start; [/CODE] Line 18 should be taken out. Line 21 should be: [CODE] start=NULL; [/CODE] Line 29 should be: [CODE] void ll<T>::add() [/CODE] Line 32 should be: [CODE] node<T>* temp = new node<T>; … | |
Re: These operators can easily be computed from the other operators: [CODE] if( a NAND b) // is equivalent to: if( ! (a && b) ) [/CODE] And so on for other operators. The C/C++ designers didn't see the point in having all operators, just the basic ones. | |
![]() | Re: Go incrementally. Start by learning [URL="http://www.cplusplus.com/doc/tutorial/basic_io/"]Basic Input/Output in C++[/URL]. Then, try to print all the digits of an input number (as an [ICODE]int[/ICODE]). To extract the digits, you are going to need a [URL="http://www.cplusplus.com/doc/tutorial/control/"]while-loop[/URL] and the second hint given to you (about 425175 % 10 = 5 and 425175 / … ![]() |
Re: First, your function definitions must always match your prototypes exactly. This means that you should have this definition of the functiony() function: [CODE] //Calling y which I call k and d is x; double functiony(double d) { return d*d*d; } [/CODE] Then, if you need to use the functiony() function … | |
Re: It's the analog of: [CODE] void test(some_type* const & A) [/CODE] So, yes, it is perfectly fine. | |
Re: What do you mean by graphics? If you mean a graphical user interface, I suggest you take a look at [URL="http://qt.nokia.com/products/"]Qt[/URL]. If you mean 3D graphics rendering, I suggest you take a look at [URL="http://www.opengl.org/"]OpenGL[/URL], [URL="http://nehe.gamedev.net/"]NeHe tutorials[/URL] are a great place to start (although out-dated a bit). And if you … | |
Re: Given the way the Fibonacci sequence works (by adding the last two values) you can pretty safely use the double type, results will not be exact (floating-point operations never are), but the range will go up to really large values (about 1.8 x 10^308). Also, the `int` and `long` types … | |
Re: Exporting classes from a DLL cannot really be done reliably because of binary compatibility issues (different compilers, compiler versions, and compilation options can produce (slightly) different binary foot-prints for the objects of a given class). The COM is (amongst other things) a strict specification of how the binary foot-print should … | |
Re: Well. My best guess to explain the difference in size is that C++ has constructs that are a lot more feature-rich than their C counter-parts. Taking a simple "Hello World" program example, in C it will just involve using the [ICODE]printf()[/ICODE] function, while the C++ version would entail constructing the … | |
Re: The compiler is GCC (for all Linux distros). With Ubuntu, you can simply run this in the terminal: [CODE] $ sudo apt-get install build-essential [/CODE] (the dollar sign is just to represent the start of the command prompt in the terminal, you shouldn't type it) The "build-essential" package will install … | |
Re: Your problem is the factor [ICODE]PI/270.0[/ICODE] which you use to transform degrees into radians. It is wrong, to convert degrees into radians, you need to use the factor [ICODE]PI/180.0[/ICODE]. This explains why your arc is only 2/3 of the angular sweep that it should have (i.e. 120 degrees instead of … | |
Re: Learn to use [URL="http://en.wikipedia.org/wiki/Indent_style"]indentation[/URL] (and space-out your code) and please [B]write[/B] in [URL="http://www.daniweb.com/forums/faq.php?faq=daniweb_policies"]correct English[/URL] (i.e. "Do post in full-sentence English" it is really annoying to read things like "it z bt hr n dr i v prbs plz hlp" instead of "It's between here and there that I have problems, … | |
Re: You need the magic of [URL="http://www.justsoftwaresolutions.co.uk/cplusplus/rvalue_references_and_perfect_forwarding.html"]Perfect Forwarding[/URL] in order to completely avoid the unnecessary copies. If you use the C++11 versions of the bind() functions (in header [ICODE]<functional>[/ICODE]), you get much better performance. First, I tried your code (with Boost.Bind): [CODE] test_for_bind tb_0; boost::bind( &test_for_bind::tamaya1, test_for_bind() )(); boost::bind( &test_for_bind::tamaya1, boost::ref(tb_0) … | |
Re: Assuming that you are using the wizard program (i.e. the GUI program, not the command-line one), then you will find the useful sections for configuration under the "input" and "preprocessor" tabs of the Expert configuration wizard. Under "Input" you can configure the directories and files to include (INPUT), the file … | |
Re: The subject of your question is really about what is called "data mining", which is a field of Database research. In other words, how to retrieve, classify, cluster, and compile statistics about data, especially large amounts of data. Frankly, this is what database engines are for, this is what they … | |
Re: Two suggestions: 1) you should make your operator overload a free-function (or friend) not a member function (this can be important for argument-dependent lookup of the correct overload). 2) to chain the operators, you need to return a reference to the printclass object from your operator. With that, you should … | |
Re: If you are interested in such matters, I suggest you read [URL="http://www.daniweb.com/software-development/cpp/tutorials/378692"]my tutorial[/URL] on ownership relations between objects in a software architecture. As a note, I don't like the term "aggregation" (in OOP) because it is fundamentally (in English) a synonym for "composition", both sharing the same definition "The combining … | |
Re: Because, in the first example, the use of inner2 is only within the definition of the function f() of inner1, while in the second example, the use of the inner2 class is in the declaration of the inner1 class. It is important to understand the difference here. Think of it … | |
Re: >>Is it possible to put a gap in a class definition? No. But if you have a use-case we can surely tell you how to solve your problem. There is basically no need to be able to do this, because anything you want to do you can solve it better … | |
Re: Your problem is with this part (in the array version): [CODE] typename std::ostream_iterator<T>(std::cout, "") [/CODE] First of all, you don't need the first [ICODE]typename[/ICODE] keyword because [ICODE]std::ostream_iterator<T>[/ICODE] is a type, not a dependent name (doesn't need the typename to resolve it). The main problem, however, is that T is an … | |
Re: The "Lesser" General Public License means that you can use the library for any application (commercial or not, open-source or not) as long as all you do is link against the library's binaries (i.e. if you don't use the source files (only headers) and you don't modify components of the … | |
Re: >>Sooner or later someone will write: const char * pchar=text, where text is an instance of my text_class. Then later, text could independantly be relocated during an insertion of characters, and pchar will points to nowhere and disaster sooner or later. Well sooner or later that "someone" will have to … | |
Re: I don't see much purpose for it. Stack-based objects are so much nicer to use than heap-allocated objects. I'd be curious to know about your use-case? The solution is to use a factory function and private constructors, as suggested by firstPerson (and, of course, smart-pointers are strongly preferred to raw-pointers). … | |
Re: I believe that the algorithm that you are supposed to arrive to is this: [TEX] \pi = 4\sum^\infty_{k=0} \frac{(-1)^k}{2k+1} = \frac{4}{1}-\frac{4}{3}+\frac{4}{5}-\frac{4}{7}+\frac{4}{9}-\cdots [/TEX] Ask yourself: What should be the starting value of pi? What should be inside the for-loop? Is the line "pi = 4 * pi" really correct? Try to … | |
Re: Here are a few comments: [CODE] int *LargestUsingPointers(const int *array, int n) { const int *p1; int *largestIndex; //you create a pointer that points nowhere, because it is uninitialized. for(p1 = &array[0]; p1 < &array[n]; p1++) { if(*p1 > array[n]) //you check if the current element is greater than an … | |
Re: The standard way to do lexical casts is to use the [ICODE]std::stringstream[/ICODE] class. Here is an example: [CODE] int ToInt(const std::string& s) { int result; std::stringstream(s) >> result; return result; }; [/CODE] The same will work with just about any type that can input/output with the standard IO streams in … | |
Re: Scott Meyers started a [URL="http://groups.google.com/group/comp.std.c++/browse_thread/thread/2bfe25800d4961e8/9545494bbb336dfa?pli=1"]huge discussion on usenet[/URL] about this topic, pretty much all the arguments you can think of there find you will. The gist of the argumentation is that there are too few use-cases and the changes required to implement them in C++ are pretty big and deep. … | |
Re: Here are a few comments: By convention, the type for all array sizes (and return value of sizeof()) is the standard size type, which is [ICODE]std::size_t[/ICODE]. So, you should probably have: [CODE] template < typename T, std::size_t elements > [/CODE] Your data member that you call "ptr" is a static … | |
Re: The basic requirement for the default assignment operator to be available for a class is that all the data members and base classes also have an assignment operator available (with the additional exception that data members of reference type also disable the default assignment operator because of the special semantics … | |
Re: You are a bit confused with the standard numbering. What you seem to refer to as C++09 is actually not C++09. The newest standard which just came out this summer is called C++11 (as in, 2011). But, it has been in the making for quite some time (since the last … | |
Re: My guess is that you enabled [URL="http://en.wikipedia.org/wiki/Back-face_culling"]back-face culling[/URL] (or didn't disable it). | |
Re: Code please? We can't really help much without seeing your attempt at it. N.B.: I hope you are aware that in C/C++ you cannot write a file-path as "C:\Program Files\my\path\file.txt", because the slash "\" character is an escape character. To actually get the "\" character, you need to write "\\" … | |
Re: First, some corrections on Fbody's comments: >>The second version is called an "implicit" declaration No. To be accurate, (8.5/14) a syntax like [ICODE]int a = 42;[/ICODE] is called a [B]copy-initialization[/B], and will be realized with an implicit type conversion if one exists (either as an implicit converting-constructor in the destination … | |
Re: Exporting a class is something that is pretty hard to do correctly. I don't recommend you try it. In general, I have not seen anyone do it on Windows (in *nix systems it's a different story). Generally, the idea is to export a factory function (and the corresponding destroying function) … | |
Re: >>But in this example I would need to be unable to make an anotherclass from outside of myclass. Is this possible and if so what is the syntax for it? Well, the code that you showed, or that of L7Sqr, achieve exactly that. Another way is to create a separate … | |
Re: >>I don't fully understand why, it's something about the way templates work "under the hood", it's just one of those things you have to do. This is a fundamental aspect of templates, and it is important to understand it: A function or class template is NOT a function or class, … | |
Re: >>what is the meaning of (&)? It means that the parameter type is "a reference to a static array", as opposed to just a static array in the first case. >>Why version one fail? That's difficult to say. I was aware of this particular problem (it is [URL="http://www.cplusplus.com/articles/D4SGz8AR/"]well known[/URL]), but … | |
Re: [QUOTE]Say you are writing a vector class. 1) You want to provide public access to checked element access function (checking that element index is withing bounds). All is great. 2) You may also want to provide access to unchecked element access function (with crash risk) to very few and selected … | |
Re: >>The program runs perfectly Your program is going to run correctly. The thing about using the "this" pointer in the initialization list is not a matter that the this pointer's value (the address of the object) is not correct, it is correct. The problem is that, at that exact point … | |
Re: I also agree with the rest of the posters that this project is pretty huge, you are basically detailing the entire construction of a library for finite-element analysis (and related code). C++ is certainly a suitable language, and you can probably fairly easily translate your excel code into C++ code … |
The End.