Like Tree2Likes
  • 2 Post By Elysia

c to c++ convert

This is a discussion on c to c++ convert within the C++ Programming forums, part of the General Programming Boards category; I want to convert the c code to c++ my code in c is // Calculate the moments to estimate ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    7

    c to c++ convert

    I want to convert the c code to c++

    my code in c is

    // Calculate the moments to estimate the position of the ball
    CvMoments *moments = (CvMoments*)mallocsizeof(CvMoments));
    cvMoments(imgYellowThresh, moments, 1);
    // The actual moment values
    double moment10 = cvGetSpatialMoment(moments, 1, 0);
    double moment01 = cvGetSpatialMoment(moments, 0, 1);
    double area = cvGetCentralMoment(moments, 0, 0);


    in c++

    cv::Moments ourMoment;//moments variable
    ourMoment=moments(imgYellowThresh); //calculat all the moment of image
    double moment10=moments.m10; //extract spatial moment 10
    double moment01=moments.m01; //extract spatial moment 01
    double area=moments.m00; //extract central moment 00

    But I am getting error at ourMoment=moments(imgYellowThresh); as identifier moments is undefined.
    Please help me in this

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,423
    This error should not surprise you. It is the same error as you get in C. "moments" in your C++ code is undefined.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    But in c I am not facing any error

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,423
    What do you intend this to do?
    ourMoment=moments(imgYellowThresh); //calculat all the moment of image
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    to get the actual position of the imgYellowThresh

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,423
    Which is equal to what in C?
    This?
    cvMoments(imgYellowThresh, moments, 1);
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    yes ...

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,423
    That's a big difference.

    ourMoment=moments(imgYellowThresh); //calculat all the moment of image
    cvMoments(imgYellowThresh, moments, 1);

    This isn't about C and C++ differences; it's more about what you have written is nonsensical and makes no sense (in C++).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    I don't know much abt c++ code but I found it some where in net.

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,423
    Then I suggest you learn C++ before you try to use it. There are tutorials on the site.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Dec 2011
    Posts
    7
    sure. thanku

  12. #12
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,293
    For the most part, C code tends to also compile using a C++ compiler.
    e.g. you can do this in C if you have a struct variable called 'moments'. Same goes for C++...
    Code:
    double moment10=moments.m10; //extract spatial moment 10
     double moment01=moments.m01; //extract spatial moment 01
     double area=moments.m00; //extract central moment 00
    Really all I see that you're trying to do here is to convert code to a more object-oriented approach.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can C# convert to C++ 6
    By xing1987 in forum C++ Programming
    Replies: 3
    Last Post: 01-26-2011, 01:46 PM
  2. convert from c to cpp
    By shaolin in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2009, 12:31 PM
  3. Convert
    By matrixhelp in forum C++ Programming
    Replies: 1
    Last Post: 03-11-2008, 12:36 PM
  4. Want to convert -ve value to +ve
    By hYph3n in forum C Programming
    Replies: 2
    Last Post: 09-05-2006, 01:52 AM
  5. Convert WAV to MID
    By E i F x 65 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-20-2002, 01:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21