0

I included "Edge_collapse_recorder.h" in my qt project m and I want to print some values on collapsing process but it show the following error when I uncommented std::cout << "collapse edge " << profile.v0_v1() << " " << << profile.v0() << " " << profile.v1() << std::endl; line :

../CM2/edge_collapse_recorder.h:102:37: error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘const halfedge_descriptor’ {aka ‘const CGAL::internal::CC_iterator<CGAL::Compact_container<CGAL::Dart<2, CGAL::CMap_linear_cell_complex_storage_1<2, 3, CGAL::Linear_cell_complex_traits<3, CGAL::Simple_cartesian<double> >, CGAL::Linear_cell_complex_bgl_min_items, std::allocator<int> >, CGAL::Void, CGAL::Boolean_tag<true> >, std::allocator<CGAL::Dart<2, CGAL::CMap_linear_cell_complex_storage_1<2, 3, CGAL::Linear_cell_complex_traits<3, CGAL::Simple_cartesian<double> >, CGAL::Linear_cell_complex_bgl_min_items, std::allocator<int> >, CGAL::Void, CGAL::Boolean_tag<true> > >, CGAL::Default, CGAL::Default>, false>’})
       std::cout << "collapse edge " << profile.v0_v1() << " " << << profile.v0()  << " " << profile.v1() << std::endl;
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~

I searched about the problem and found that I have to overload << operator , then I added the following to onCollapssing method :

 std::ostream& operator<<(std::ostream& os, const Edge_collapse_recorder& t) {
                      os <<  << "collapse edge " << t.v0_v1() << " " << << t.v0()  << " " << t.v1();
                     return os;
                 }

but it's showing the following error : function-definition is not allowed here before ‘{’ token"

  void OnCollapsing(Profile const& profile
                      ,boost::optional<Point_3>  placement
                      )
    {
      visitor.OnCollapsing(profile,placement);

      if ( placement ){
           std::ostream& operator<<(std::ostream& os, const Edge_collapse_recorder& t) {
                     os <<  << "collapse edge " << t.v0_v1() << " " << << t.v0()  << " " << t.v1();
                     return os;
                 }

        Record record;
        record.v0 = profile.v0();
        record.v1 = profile.v1();
        record.p0 = profile.p0();
        record.p1 = profile.p1();
        halfedge_descriptor hd = profile.v0_v1();

        record.oppa = (! is_border(hd,recorder.sm))
          ? target(next(hd, recorder.sm),recorder.sm)
          : boost::graph_traits<LCC>::null_vertex();

        record.oppb = (! is_border(opposite(hd, recorder.sm),recorder.sm))
          ? target(next(opposite(hd, recorder.sm), recorder.sm),recorder.sm)
          : boost::graph_traits<LCC>::null_vertex();

        recorder.records.push_back(record);
      }
    }
n.m
  • 485
  • 1
  • 5
  • 15
  • First, don't post code as images. Code is text, copy and paste it. To otherwise is to hinder search-ability and make things harder on the visually impaired. Secondly, the image contains several semantic and syntactic issues that suggest you probably need a [good book about C++](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – StoryTeller - Unslander Monica Mar 10 '19 at 10:41
  • 1
    Functions can't be defined in the bodies of other functions. But that's exactly what the offending line is trying to do - defining, and not calling, a function named `operator<<()` in the body of `OnCollapsing()`. – Peter Mar 10 '19 at 11:26
  • @Peter ok , I got what you mean , but how can I use cout<< to print value within OnCollapsing() method ? – n.m Mar 12 '19 at 11:19
  • 1
    `cout << value_you_want_output`. What makes you thing you would use "cout <<" within `OnCollapsing()` differently than in any other function? Right at the top of your question you stated you added some text to `OnCollapsing()` - why did you use that particular text? – Peter Mar 12 '19 at 11:28
  • @Peter you are right , I tried now cout<< something and working correctly . I thought the problem in cout cause of the following error while printing profile.v0() value : error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream’ and ‘const halfedge_descriptor’ I updated the post with the error showing while printing profile.v0() – n.m Mar 12 '19 at 12:33

1 Answers1

4

That commented-out line will never compile. It has two consecutive << operators.

As for the error message, you are defining the function

std::ostream& operator<<(std::ostream& os, const Edge_collapse_recorder& t)

(and not just declaring it) inside another function. Nested function definitions are not allowed in C++. To do what you want (and I am not sure if it's a good idea), put the function definition before the OnCollapsing function.

TonyK
  • 16,761
  • 4
  • 37
  • 72
  • 1
    Given that the `OnCollapsing()` function defines but never calls the `operator<<()` function, there is no need to define the `operator<<()` before `OnCollapsing()`. The only constraint is that the definitions not be nested. There may need to be a declaration visible, but the definition does not need to be. – Peter Mar 10 '19 at 11:28