CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

Search:

Type: Posts; User: phl

Page 1 of 3 1 2 3

Search: Search took 0.06 seconds.

  1. Re: pointer to a pointer creating dynanic 2d array for that pointer

    Corrections are in red.



    int main(){
    //i can do it like this
    int** p;
    p = new int*[10];
    for(int i=0;i<10;i++)
    p[i] = new int[10];
  2. Replies
    11
    Views
    1,418

    Re: still need HELP::Operator Overloading + Constructors

    Yes, passing is the right choice of word, not converting.
  3. Replies
    11
    Views
    1,418

    Re: HELP::Operator Overloading + Constructors

    Because it first creates a temporary of abc by calling constructor abc(char*), and then that temporary is passed by value to operator=(abc). Maybe you can run a debugger to see what's happening.

    ...
  4. Replies
    11
    Views
    1,418

    Re: still need HELP::Operator Overloading + Constructors

    I don't understand what you mean by "without checking its type", but here is what I think is happening.



    anotherObject = "i Know why this works now!!!"; //
    anotherObject = 8; ...
  5. Replies
    11
    Views
    1,312

    Re: bind2nd and multiple vectors

    Is std::vector<XButton*> the type of "buttons" in the following code ?



    std::for_each(
    buttons.begin(),
    buttons.end(),
    std::bind2nd(std::mem_fun_ref(&XButton::Update), event_));
  6. Replies
    7
    Views
    873

    Re: Value from a functions

    solution[i] = new_y;


    You are assigning new_y, which is of type double*, to solution[i], which is of type double.
  7. Replies
    5
    Views
    1,359

    Re: delete element from a vector

    Strictly speaking, this will not give the same result as the for-loop version when there is more than one element equal to "observer". The erase/remove idiom erases all of them, but the for-loop...
  8. Replies
    6
    Views
    1,421

    Re: Djkstras algorithm help!

    You might want to take a look at boost graph library.

    http://www.boost.org/libs/graph/doc/table_of_contents.html

    You can use one of the shortest path algorithms on your problem and compare the...
  9. Replies
    6
    Views
    993

    Re: returning char arrays from fucntion

    Make dashReplace return char*.

    Alternatively, make dashReplace return nothing (return void). Since it is passing a pointer to line[12] as an argument, after dashReplace (line) is called, line[12]...
  10. Thread: Header Problems

    by phl
    Replies
    2
    Views
    842

    Re: Header Problems

    1. In input.h, add "extern" to declare variables. Without "extern", it means you are defining variables, and since header files are most likely included multiple times, the compiler will complain the...
  11. Replies
    3
    Views
    2,617

    Re: std::for_each and std::mem_fun

    Use bind2nd. In your example, mem_fun_ref returns a functor that takes 2 arguments, and bind2nd binds the second one to 0.



    std::for_each (tests.begin (),
    tests.end (),...
  12. Thread: sorting a vector

    by phl
    Replies
    5
    Views
    669

    Re: sorting a vector

    Does it work if you change the order of the edges in the dataset?
    For example, if you swap the 1st and the 6th edge, does it give the same results?
    It seems to me that your code will print the 2...
  13. Replies
    6
    Views
    1,484

    Re: STL elegance - sorting a vector into a map

    Your code is already simple enough (just 2 lines, if you get rid of the braces) so there is no need to make it more elegant. Also, I think your code might be better than the one using operator[], in...
  14. Thread: sorting a vector

    by phl
    Replies
    5
    Views
    669

    Re: sorting a vector

    After comparing the weights, call a function that swaps the source and target if source > target (note that the original Edge is constant).



    Edge order(const Edge& e) {
    Edge tmp(e);

    if...
  15. Replies
    6
    Views
    1,484

    Re: STL elegance - sorting a vector into a map

    I agree. The original code is much easier to read, especially for those who don't use boost or STL often.
  16. Replies
    6
    Views
    1,484

    Re: STL elegance - sorting a vector into a map

    If you are wiling to use boost::bind, the following code should accomplish what you want to do.



    transform(objVec.begin(), objVec.end(), inserter(objMap, objMap.begin()),
    ...
  17. Replies
    8
    Views
    643

    Re: How can I write this code shorter

    Assuming you have a member of type B*,


    class A {
    public:
    B* getInstB() {
    return b;
    }
    private:
    B* b;
  18. Replies
    5
    Views
    718

    Re: 5 == 10682564? Dynamic Array class

    If you are looking for an array you can resize, you might want to look into STL containers, such as vector or deque.

    http://www.cplusplus.com/reference/stl/
  19. Thread: Find two character

    by phl
    Replies
    2
    Views
    606

    Re: Find two character

    Use string or an array of size 2 to record the two characters previously read.



    char ch;
    string pre(" ");

    while (TheFile.get(ch)) {
    if (pre == ". ")
    TheCopy.put(toupper(ch));
  20. Replies
    11
    Views
    1,167

    Re: gcc ignores const before template parameter?

    You can write a template class as follows.



    template<typename T>
    struct ToConstRef {
    typedef const T& _Type;
    };

    template<typename T>
  21. Replies
    7
    Views
    1,145

    Re: Error when running a sudoku code

    I cannot be sure since I don't understand how you are approaching the problem, but the following line looks like a mistake to me.


    while...
  22. Replies
    36
    Views
    3,388

    Re: Can STL sets do range queries?

    If the set contains pointers, use "mem_fun" instead. The following link gives an example.

    http://www.sgi.com/tech/stl/mem_fun_t.html

    The approach using remove_copy_if, as well as the one using...
  23. Replies
    36
    Views
    3,388

    Re: Can STL sets do range queries?

    No, it doesn't.

    http://www.sgi.com/tech/stl/set.html
  24. Replies
    36
    Views
    3,388

    Re: Can STL sets do range queries?

    You can use mem_fun_ref when the predicate is a member function of the object stored in set.



    #include <iostream>
    #include <algorithm>
    #include <iterator>
    #include <set>

    using namespace...
  25. Re: Templated function pointers as function parameters

    You don't need to make it a template. Just make it a plain old function.



    class C {
    public:
    int f(char) {}
    };

    template <class Cl, typename R, typename P1>
Results 1 to 25 of 51
Page 1 of 3 1 2 3





Click Here to Expand Forum to Full Width

Featured