User Profile

Collapse

Profile Sidebar

Collapse
mkborregaard
mkborregaard
Last Activity: Nov 18 '08, 06:56 AM
Joined: Sep 12 '07
Location: Denmark
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • mkborregaard
    replied to C++ help
    in C
    Test for '== 9999' (or better '>=9999') before setting 'largest' to 'value'. I do not see why you could not use 'if (value < smallest) value = smallest' to find the smallest? - alternatively you could use
    Code:
    smallest = min(smallest, value);
    But nothing will work unless you initialize smallest and largest properly, e.g.
    Code:
     smallest = 9998; largest = -9998;
    See more | Go to post

    Leave a comment:


  • mkborregaard
    replied to templated constructor for nested classes
    in C
    OK. Why would you want to do it any other way?
    See more | Go to post

    Leave a comment:


  • OK. I was just wondering whether your problem was related to the uninitialized Maze* pointer (which i guess you intend to initialize in the MazeThing constructor to point to the Maze object owning MazeThing). Cool you got it solved, though....
    See more | Go to post

    Leave a comment:


  • How does your MazeThing constructor look?
    See more | Go to post

    Leave a comment:


  • mkborregaard
    replied to templated constructor for nested classes
    in C
    Are you trying to divide the code into a header and a .cpp file? When implementing templated classes, the entire class should be kept in one file. Try implementing the constructor inline.
    See more | Go to post

    Leave a comment:


  • mkborregaard
    replied to beginner Cout
    in C
    By the way, it looks like you are saying that when you run within the Borland IDE you do not have problems, but otherwise your window shuts down too fast. If that is your problem, you should end the main() function (before return 0;) with the line
    [code=cpp]system("PAUSE")[/code] if your are on ms windows, or just [code=cpp]cin.get();[/code]
    That will make sure the window stays open until you have seen the results.
    ...
    See more | Go to post

    Leave a comment:


  • mkborregaard
    replied to matrix multiplication
    in C
    There are several ways of doing matrix multiplication in c++, depending what your need is. You can program it from scratch - then you need a data structure to hold your matrix (e.g. an array[][] or a std::vector<std ::vector<double > >), and then work from there. This is easiest and probably best if you just want to play with it.
    There are also several class libraries available on the internet that provides pre-programmed functions...
    See more | Go to post

    Leave a comment:


  • mkborregaard
    replied to beginner Cout
    in C
    You do not define the nAverage function correctly - what your code does is telling the compiler that nAverage is a variable of type int. You then give this int variable the value a+b+c, which are undefined.
    Instead nAverage should be a function returning a double (since the average is not likely to be an integer).
    The correct way of defining your function is: [CODE=cpp]double nAverage (int a, int b, int c) {return (a+b+c)*1.0/3;}[/...
    See more | Go to post

    Leave a comment:


  • mkborregaard
    replied to cast of vectors
    in C
    Thanks!
    I did a templated wrapper class, that uses the transform() algorithm - it is a bit heavy, but it works. It is very interesting for me to hear about the reputation of casts, since I am (of course) interested in improving my coding style.
    See more | Go to post

    Leave a comment:


  • mkborregaard
    replied to cast of vectors
    in C
    I stand corrected :)
    Could you elaborate on what is wrong with the word 'cast'?
    I am using a matrix calculation library from the web, which only accepts matrices of type double, to implement some statistics. However, all my statistics are performed on integer numbers, as my data are counts - I believe it should cause no problems, since int-to-double conversions go painlessly, and the return types are supposed to be doubles anyway....
    See more | Go to post

    Leave a comment:


  • mkborregaard
    started a topic cast of vectors
    in C

    cast of vectors

    Is there an easy way to cast my vector<int> to vector<double>, without generating a new vector and copying and typecasting each element from one to the other?
    I have a class constructor that takes a bunch of vector<doubles> , and it is impractical to template the entire class...
    See more | Go to post

  • Cool enough,
    I will abstain from spoonfed code.
    Mathanna,
    you open the file as a std:ifstream ; then you can read the file using the >> operator, and fill the 2Dvector using [CODE=cpp]myArray.push_ba ck();[/CODE]
    alternatively, you can construct the vector as:
    [CODE=cpp]std:vector<std: vector<int> > myArray(cols,st d:vector<int>(r ows));[/CODE]
    and just fill it in your for loops using...
    See more | Go to post

    Leave a comment:


  • Hi Mathanne,
    It is not clear for me what you want to acheive exactly, but let me try to give you a few points:
    If programming in c++, you should use a <vector> instead of an array, it is a much more easy-to-use and powerful container. You could define it as:
    [CODE=cpp]#include <vector>
    typedef std:vector<std. vector<int> > 2Dvector;
    2Dvector myArray;[/CODE]
    provided that it is int you...
    See more | Go to post

    Leave a comment:


  • Yes!
    Finally it works :) thanks!
    Michael
    See more | Go to post

    Leave a comment:


  • Thanks, but I do not see how that could work?
    There is an implicit this->cell_iter++ in line 68. My iterator contains two other iterators:
    [CODE=cpp]
    Grid<T>::iterat or : public Row<T>::iterato r
    {
    typename std::vector<Row <T> >::iterator row_iter;
    typename Row<T>::iterato r cell_iter;
    //...
    };[/CODE]

    row_iter points at a row in the Grid, and cell_iter...
    See more | Go to post

    Leave a comment:


  • mkborregaard
    started a topic problem overloading the ++ operator of an iterator
    in C

    problem overloading the ++ operator of an iterator

    Hi,
    I have the weirdest problem, and I can not see what is going wrong.
    I have made a 2d container class, and am implementing an iterator for that class. However, the ++ operator is behaving very strange. The implementation looks like this (there is a lot of code, but I have only included it all for consistency. The problem is quite small and local):


    [CODE=cpp]
    template<typena me T> class Row<T>...
    See more | Go to post

  • Thanks!
    That solved my problem :)
    See more | Go to post

    Leave a comment:


  • You're right, that compiles without problems on my system too, which means that noone on the forum had any chance to find the error, sorry.
    The error does indeed seem to be with the #includes - the problem is generated when the three friend classes in turn includes AreaMap, because each class contains a reference to AreaMap - and class AreaMap has not yet been declared at that point. I must be doing something wrong with the includes; how does...
    See more | Go to post

    Leave a comment:


  • No, as far as I can tell, the <map> file is guarded by a
    [CODE=cpp] #ifndef MAP_H[/CODE] tag, and I do not use the STL container Map anywhere. Changing the guard token to [CODE=cpp]#ifndef AREAMAP_H_INCLU DED[/CODE] does not change the problem.
    The AreaMap class used to be called Map, but I thought it might collide, so I changed the name, and created a completely new project and copied all my code files into that, to make sure...
    See more | Go to post

    Leave a comment:


  • ISO C++ forbids declaration of 'Areamap' with no type

    Hi,
    I am getting an error message from MinGW that I just cannot figure what causes.
    The error message is:
    "Line 16: ISO C++ forbids declaration of 'AreaMap' with no type"
    My code is:[CODE=cpp]

    #ifndef RANGE_H_INCLUDE D
    #define RANGE_H_INCLUDE D
    #include "grid.h" //for type: presenceGrid
    #include <vector>
    #include "AreaMap.h"

    ...
    See more | Go to post
    Last edited by Banfa; Oct 16 '07, 10:36 PM. Reason: Added =cpp to make the C++ code tags
No activity results to display
Show More
Working...