I can not resolve "error: conflicting types for... "

View: New views
3 Messages — Rating Filter:   Alert me  

I can not resolve "error: conflicting types for... "

by mahmoodn :: Rate this Message:

| View Threaded | Show Only this Message

Hello,
Why I get this confusing error:

VVc_demo.cpp: In function `bool read_polygons(const char*, Polygons_list_2&,
   Bbox_2&)':
VVc_demo.cpp:617: error: conflicting types for `read_polygons(const char*,
   Polygons_list_2&, Bbox_2&)::domain ifile'
VVc_demo.cpp:598: error: previous declaration as `std::ifstream ifile'
VVc_demo.cpp:617: error: syntax error before `>>' token
VVc_demo.cpp:629: error: no match for 'operator>>' in 'ifile >> n_vertices'

the function that has problem is:

bool read_polygons (const char *filename, Polygons_list_2& polygons, Bbox_2& bbox)
{
  // Open the input file.
  std::ifstream          ifile (filename);
  std::ofstream         ofile ("domain.txt", 'w');


  if (! ifile.is_open()) {
    std::cerr << "Failed to open <" << filename << ">." << std::endl;
    return (false);
  }

  // Read the number of input polygons.
  int                    n_polygons;
  struct domain {
        float xMin;
        float xMax;
        float yMin;
        float yMax;
  }

  ifile >> n_polygons;

  // Read the polygons.
  int                    n_vertices;
  Rational               x, y;
  std::list<Rat_point_2> vertices;
  int                    i, j;
  bool domainFlag = true; // for extracting domain min max points. first usage is true

  for (i = 0; i < n_polygons; i++) {
    // Read the number of vertices in the current polygon.
    ifile >> n_vertices;

    // Read the vertices.
    vertices.clear();

    for (j = 0; j < n_vertices; j++) {
      ifile >> x >> y;
      vertices.push_back (Rat_point_2 (x, y));
    }

    // Create a polygon and append it to the output list.
    Rat_polygon_2        pgn (vertices.begin(), vertices.end());

    if (! pgn.is_simple()) {
      std::cerr << "Error - Polygon no. " << i + 1  << " is not simple." << std::endl;
      return (false);
    }

        // for first polygon (domain) we have to extract boundary point
        // so that generated random milestones have to fit in domain
        if ( domainFlag ) {
                domain.xMin = pgn.left_vertex_2();
                domain.xMax = pgn.right_vertex_2();
                domain.yMin = pgn.bottom_vertex_2();
                domain.yMax = pgn.top_vertex_2();
            if (ofile.is_open()) {
                        ofile << domain.xMin << domain.xMax
                                  << domain.yMin << domain.yMax;
       }
           ofile.close();
                domainFlag = false; // for other polygons, we do not need it
        }

    polygons.push_back (pgn);

    // Update the bounding box.
    if (i == 0)
      bbox = pgn.bbox();
    else
      bbox = bbox + pgn.bbox();
  }

  // Successful termination.
  ifile.close();
  return (true);
}

Re: I can not resolve "error: conflicting types for... "

by Andrew Haley :: Rate this Message:

| View Threaded | Show Only this Message

mahmoodn writes:
 >
 > Hello,:-)
 > Why I get this confusing error:confused::
 >
 > VVc_demo.cpp: In function `bool read_polygons(const char*, Polygons_list_2&,
 >    Bbox_2&)':
 > VVc_demo.cpp:617: error: conflicting types for `read_polygons(const char*,
 >    Polygons_list_2&, Bbox_2&)::domain ifile'
 > VVc_demo.cpp:598: error: previous declaration as `std::ifstream ifile'
 > VVc_demo.cpp:617: error: syntax error before `>>' token
 > VVc_demo.cpp:629: error: no match for 'operator>>' in 'ifile >> n_vertices'
 >
 > the function that has problem is:

Please give us a stand-alone test case that shows the problem.

Andrew.

--
Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, UK
Registered in England and Wales No. 3798903

Re: I can not resolve "error: conflicting types for... "

by mahmoodn :: Rate this Message:

| View Threaded | Show Only this Message

I did not what was the problem exactly, but I change
   std::ofstream         ofile ("domain.txt", 'w');
to:
  std::ofstream   ofile;
  ofile.open( "domain.txt");

and it compiled correctly.

it is strange but got solved


Andrew Haley wrote:
mahmoodn writes:
 >
 > Hello,:-)
 > Why I get this confusing error:confused::
 >
 > VVc_demo.cpp: In function `bool read_polygons(const char*, Polygons_list_2&,
 >    Bbox_2&)':
 > VVc_demo.cpp:617: error: conflicting types for `read_polygons(const char*,
 >    Polygons_list_2&, Bbox_2&)::domain ifile'
 > VVc_demo.cpp:598: error: previous declaration as `std::ifstream ifile'
 > VVc_demo.cpp:617: error: syntax error before `>>' token
 > VVc_demo.cpp:629: error: no match for 'operator>>' in 'ifile >> n_vertices'
 >
 > the function that has problem is:

Please give us a stand-alone test case that shows the problem.

Andrew.

--
Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, UK
Registered in England and Wales No. 3798903