User Profile

Collapse

Profile Sidebar

Collapse
chroot
chroot
Last Activity: Jan 30 '08, 11:38 AM
Joined: Nov 21 '07
Location: Switzerland
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Maybe the compiler would optimize if you wrote (in main)

    Code:
    RVO rvo=MyMethod(5);
    With two lines, the compiler has no other choice then to use the default constructor, then replace with the copy constructor.
    See more | Go to post

    Leave a comment:


  • chroot
    replied to Error : Not all code paths return a value
    in .NET
    Your function has a return value (string). The function must return a value in any case. Now if the program doesn't enter your if, it will reach the end of the function, where there's no return value => error.

    The compiler is smart enough for this, though:

    Code:
    int abs(n) {
    if (n > 0)
      return n;
    else
      return -n;
    }
    There's something returned in any case,...
    See more | Go to post

    Leave a comment:


  • There is an equivalent to the repeat ... until loop:

    int i=0;
    do {

    ++i;
    cout << i << endl;

    } while (i<10);

    There needs to be a ; after while.
    I prefer to use the normal while loop when possible, as it's faster to understand than varying while / do while loops.
    See more | Go to post

    Leave a comment:


  • chroot
    replied to Integration of a mathematical expression
    in C
    Integrating a mathematical function is much too specific a function for the Standard Library.

    Are you looking for a function to integrate symbolically, e.g.

    2*x -> results of function: x^2

    or for a function to find the value of an integral on some domain numerically, e.g.

    Integral from 0 to 1 of x^3 -> result of function: 0.249967

    Those are fundamentally different methods...
    See more | Go to post

    Leave a comment:


  • chroot
    replied to c++ code to read xml file
    in C
    Hi

    I've used the XML Parser of Frank Vanden Berghen (here).

    It's easy to learn and to integrate into your program (just two files), and under the BSD license.

    Give it a try, I found it very useful
    See more | Go to post

    Leave a comment:


  • chroot
    replied to A quadratic equation in c
    in C
    Why do you have the user enter d?
    Apart from that, the program should work
    See more | Go to post

    Leave a comment:


  • chroot
    started a topic Inheritance and enum
    in C

    Inheritance and enum

    Hello

    Does anyone have a suggestion how to solve this in a better way?

    I have an abstract class A containing an std::vector<> of Mat (other class; not important here), with an enum specifying what sort of information the vector holds at each index.


    class A {

    public:
    enum matIndex {

    goalA = 0,
    goalP,
    weightP,
    ...
    See more | Go to post

  • chroot
    replied to binomial coefficients
    in C
    That's it exactly. When you calculate the denominator separately, you get to huge numbers, and dividing them results in numerical errors (might even get an overflow with big numbers).

    So to calculate ( n *( n-1) * ... * (n-k+1) ) / ( k * (k-1) * ... * 1 ), you need to always take a pair of multiplicands together:

    n/k * (n-1)/(k-1) * ... * (n-k+1)/1

    to avoid these errors.

    To make it even...
    See more | Go to post

    Leave a comment:


  • chroot
    replied to E2353 Class '.. ' is abstract because of...
    in C
    Well the easiest way would be to just add more arguments to your function:

    Code:
    create( commonArgument1, commonArgument2, ..., CurrentAccountArgument1, CurrentAccountArgument2, SavingAccountArgument1);
    Than, in the overloaded functions, you just ignore the arguments that concern other classes (CurrentAccount ::create will ignore SavingAccountAr gument1), and give any data when calling this function.
    ...
    See more | Go to post

    Leave a comment:


  • Thank you for the fast reply

    1) Mostly I'm trying to make things tidier, as there are already a lot of libraries that I have to link every time. It would work just putting the library at the end of the path, just fells overdone. I was wondering if there's a better way.

    2) Yes, that's about what I'm trying to do. A library would be good, but when I create a library, are the libraries it uses linked into it? I thought...
    See more | Go to post

    Leave a comment:


  • chroot
    replied to E2353 Class '.. ' is abstract because of...
    in C
    Well, the important thing about using polymorphism (which the exercise is about, I suppose), is that the base class ( Account ) can only have functions and members that every class that inherits from it has too.

    So, if you want to be able to call Accounts[0]->create( ... ), you must have one function create which takes the same arguments for each class. Only then it is possible to call the function for any Account (CurrentAccount...
    See more | Go to post

    Leave a comment:


  • chroot
    replied to E2353 Class '.. ' is abstract because of...
    in C
    Hi

    As I see it, you have two functions void create(...) = 0;

    You implement one of them in CurrentAccount and one in SavingAccount, but you would have to implement both functions in both classes to stop them from being abstract.

    A class is abstract until all functions virtual ... =0; of all base classes are implemented.

    Why do you need both functions create to be virtual .. = 0; ?
    See more | Go to post

    Leave a comment:


  • Linking static library into a .o-file instead of the executable

    Hello

    I'm not sure this is the right place to ask, hope it's not too far off.

    I'm using a big external library in my project, but need it only in one class. I'd like to link the library into the .o-file.

    I realise this is not how .o-files normally work, but it would be handy to realize it in this case. I would then only have to link to my own .o-file in every executable I need it, and not search the library...
    See more | Go to post
No activity results to display
Show More
Working...