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

  • SEARCH
  • Home
  • 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 7766907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:32:32+00:00 2026-06-01T15:32:32+00:00

I spent around two hours on that problem, and I have visited these stackoverflow

  • 0

I spent around two hours on that problem, and I have visited these stackoverflow questions before:

c++ passing a const object reference to a function

Passing const& as a function argument

both did not help me, so I am specifying my problem here:

1) I have a class Polygon that stores Point2Ds in a list. The class has among others two member functions:

public:    
  std::pair<Point2D,Point2D> closestPts()  const;
private:
  Tripel const& findClosestPts (std::vector<Point2D> const& P,
                                std::vector<Point2D> const& X,
                                std::vector<Point2D> const& Y) const;

2) The class also contains a struct Triple that is the return value of the function findClosestPts. I need that, because the function needs to return two points and one distance:

struct Tripel {
  Point2D pt1;
  Point2D pt2;
  float   dist;
};

The problem is now in the implementation of Polygon.cpp. This is my (current) code for the two above mentioned functions:

std::pair<Point2D,Point2D> Polygon::closestPts() const {
   ...
   int size = m_points.size();
   std::vector<Point2D> P (size);
   std::vector<Point2D> X (size);
   std::vector<Point2D> Y (size);
   ...
   // some manipulation of the vectors, filling them with Point2D
   // at this point, I have three non-const std::vector<Point2D>

   // try to call the other function       
   Tripel closPts = findClosestPts(P, X, Y);
   ...
}

Tripel const& findClosestPts (std::vector<Point2D> const& P, std::vector<Point2D> const& X, std::vector<Point2D> const& Y) const {
   ...
}

The compiler error is:

error: non-member function 'const Tripel& findClosestPts(...)' cannot have cv-qualifier

So I guess I am not allowed to make this function const, because it returns a struct. Is that true?

Anyways, I changed the function signature to this:

Tripel const& findClosestPts (std::vector<Point2D> const& P,
                              std::vector<Point2D> const& X,
                              std::vector<Point2D> const& Y);

So, the function is not const anymore. This leads to the following compiling error:

error: passing 'const Polygon' as 'this' argument of 'const Tripel& Polygon::findClosestPts(...)' discards qualifiers [-fpermissive]

I do not know, what to do now. I tried pretty much everything, deleting all the const statements, changing them around, making findClosestPts public, making it const again, making the three std::vectors const before passing them into the other function … but everything leaded to (different) compiling errors.

So my question is, how do I need to write the two functions, to achieve the following: I want to have a function closestPoints() that is a public member function and that returns the pair of the two closest points. For that it needs an auxilary, private member function findClosestPts(vector1, vector2, vector3) that returns the above mentioned struct Triple?

I would be happy about help, because I am stucked here since a while :/

  • 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-06-01T15:32:33+00:00Added an answer on June 1, 2026 at 3:32 pm

    You can make it const, you just forgot to qualify the name in the implementation.

              //class name
                    ||
                    \/
    Tripel const& Polygon::findClosestPts (std::vector<Point2D> const& P, 
               std::vector<Point2D> const& X, std::vector<Point2D> const& Y) const
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, that is joined in some way. I've spent the last
I have spent the afternoon trying to wrap my mind around how to translate
The situation is that I've spent some time messing around with some experimental code.
I have a project that needs to incorporate two third-party libraries, libA and libB.
I just spent around an hour implementing the android market licencing tools into my
I spent some time looking around, and all I could find is Jython. It's
I've spent some time searching around how to configure NHibernate's FlushMode so it could
I've spent a decent amount of time on the web and messing around in
Spent some time troubleshooting a problem whereby a PHP/MySQL web application was having problems
I've spent two days on this and I still can't find the cause of

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.