Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7658441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:12:08+00:00 2026-05-31T13:12:08+00:00

I am developing a C++ application using NetBeans 6.9 on Ubuntu 11.04. I am

  • 0

I am developing a C++ application using NetBeans 6.9 on Ubuntu 11.04. I am using OpenCV 2.3.1. I was wondering if someone could tell me what is wrong with this code.


void AddTriangle(CvPoint buf[3], set< Triangle > &V)
{
Triangle triangle;
int inc;

for (inc=0; inc<3; ++inc)
{
    triangle.v[inc].x=buf[inc].x;
    triangle.v[inc].y=buf[inc].y;
}
V.insert((const Triangle) triangle);

}

I get the following error message when I try to compile.


from /usr/include/c++/4.5/bits/locale_classes.h:42,
from /usr/include/c++/4.5/bits/ios_base.h:43,
from /usr/include/c++/4.5/ios:43,
from /usr/include/c++/4.5/istream:40,
from /usr/include/c++/4.5/sstream:39,
from /usr/include/c++/4.5/complex:47,
from /usr/local/include/opencv2/core/core.hpp:59,
from ../../OpenCV-2.3.1/include/opencv/cv.h:64,
from ../../OpenCV-2.3.1/include/opencv/cv.hpp:50,
from ../../DraculaFiles/TwoDTriangulation.cpp:12:
/usr/include/c++/4.5/bits/stl_function.h: In member function ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = sTriangle]’:
In file included from /usr/include/c++/4.5/string:50:0,
/usr/include/c++/4.5/bits/stl_tree.h:1184:4: instantiated from ‘std::pair, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(const _Val&) [with _Key = sTriangle, _Val = sTriangle, _KeyOfValue = std::_Identity, _Compare = std::less, _Alloc = std::allocator]’
/usr/include/c++/4.5/bits/stl_set.h:408:29: instantiated from ‘std::pair, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = sTriangle, _Compare = std::less, _Alloc = std::allocator, typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator = std::_Rb_tree_const_iterator, value_type = sTriangle]’

Triangle is defined as follows.

typedef struct sTriangle
{
CvPoint v[3];
} Triangle;

Any help would be greatly appreciated,
Peter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:12:08+00:00Added an answer on May 31, 2026 at 1:12 pm

    To put Triangle into a set, you have to implement comparison operator. Otherwise the set cannot tell which values are equal and which are different.

    typedef struct sTriangle
    {
    CvPoint v[3];
    bool operator<(const sTriangle& other) const;
    } Triangle;
    
    bool sTriangle::operator<(const sTriangle& other) const
    {
       // compare 'this' with 'other'
    }
    

    For the implementation of less operator, you can inspire here.

    Edit: you can implement the less operator even without modifying sTriangle structure:

    typedef struct sCvPoint {
    int x;
    int y;
    } CvPoint;
    
    typedef struct sTriangle
    {
    CvPoint v[3];
    } Triangle;
    
    bool operator==(CvPoint const& left, CvPoint const& right)
    {
        return left.x == right.x && left.y == right.y;
    }
    
    bool operator<(CvPoint const& left, CvPoint const& right)
    {
        return left.x == right.x
            ? left.y < right.y
            : left.x < right.x;
    }
    
    bool operator<(Triangle const& left, Triangle const& right)
    {
        return left.v[0] == right.v[0]
            ? left.v[1] == right.v[1]
                ? left.v[2] < right.v[2]
                : left.v[1] < right.v[1]
            : left.v[0] < right.v[0];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple application using netbeans for developing and maven for building et
I am using Netbeans IDE (J2ME) for developing a mobile application, a dictionary which
I'm developing application using backbone.js & jquery. I have following code in model: runReport:
Currently developing an application using the newest version of symfony, obtained through PEAR. This
I am developing an application in Netbeans, and it is using JavaDB. I can
I'm developing a j2me application using Netbeans IDE and LWUIT library. I need to
I'm developing a j2me application using Netbeans IDE and LWUIT library. I'm using Persian
I am developing a web application using JSF on Netbeans 7.0. I have created
I am developing a web application using NetBeans and MySQL as the database. I
I am developing a small desktop application in JAVA using Netbeans. I place a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.