compile error of type unmatch, plz help
eric lin
fsshl@luxmail.com
Thu Nov 4 03:54:00 GMT 2010
--- iant@google.com wrote:
From: Ian Lance Taylor <iant@google.com>
To: <fsshl@luxmail.com>
Cc: <gcc@gcc.gnu.org>
Subject: Re: not quite polymorphism
Date: Mon, 01 Nov 2010 22:01:09 -0700
"eric lin" <fsshl@luxmail.com> writes:
> I am using 4.4.3, could anyone have experience to use different(newer)
> version of gcc/g++ so it can distinquish different useage of same
> variable, i.e. Window, in my case without response by compile time
> error?
dear gcc programers:
I already replace "Window" by "Window2" in Mr. Bjarne
Stroustrup's book
"programming
Principles and practice using c++"
as the result, my g++ 4.4.3, indeed take off that
" name ambiguous error"
/*****-------------------------------------------------------*/
/usr/include/c++/4.4/backward/backward_warning.h:28:2: warning:
#warning This file includes at least one deprecated or antiquated
header which may be removed without further notice at a future date.
Please use a non-deprecated interface with equivalent functionality
instead. For a listing of replacement headers and interfaces, consult
the file backward_warning.h. To disable this warning use
-Wno-deprecated.
In file included from Simple_window.cpp:7:
Simple_window.h:17: error: reference to âWindowâ is ambiguous
/usr/include/X11/X.h:96: error: candidates are: typedef XID Window
Window.h:26: error: class Graph_lib::Window
Simple_window.h:17: error: reference to âWindowâ is ambiguous
/usr/include/X11/X.h:96: error: candidates are: typedef XID Window
Window.h:26: error: class Graph_lib::Window
Simple_window.cpp: In constructor
âSimple_window::Simple_window(Point, int, int, const String&)â:
Simple_window.cpp:12: error: reference to âWindowâ is ambiguous
/usr/include/X11/X.h:96: error: candidates are: typedef XID Window
Window.h:26: error: class Graph_lib::Window
/*-------------------------------------------------------------------*/
but, there still are some compile error
---------------------------------------
root@eric-laptop:/home/eric/BStrou/usingC++4/code/Chapter12# g++ -Wno-deprecated chapter.12.3.cpp Simple_window.cpp GUI.cpp Window.cpp -lfltk
Window.cpp:17: error: prototype for ‘Graph_lib::Window2::Window2(int, int, const String&)’ does not match any in class ‘Graph_lib::Window2’
Window.h:26: error: candidates are: Graph_lib::Window2::Window2(const Graph_lib::Window2&)
Window.h:31: error: Graph_lib::Window2::Window2(Point, int, int, const std::string&)
Window.h:29: error: Graph_lib::Window2::Window2(int, int, const std::string&)
Window.cpp:25: error: prototype for ‘Graph_lib::Window2::Window2(Point, int, int, const String&)’ does not match any in class ‘Graph_lib::Window2’
Window.h:26: error: candidates are: Graph_lib::Window2::Window2(const Graph_lib::Window2&)
Window.h:31: error: Graph_lib::Window2::Window2(Point, int, int, const std::string&)
Window.h:29: error: Graph_lib::Window2::Window2(int, int, const std::string&)
--------------------------------------------------------------------------------------
here is my window.h and window.cpp
/*****************************************************************/
-----------------------------------Window.h---------------------
//
// This is a GUI support code to the chapters 12-16 of the book
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//
#ifndef WINDOW_GUARD
#define WINDOW_GUARD
#include <string>
#include <vector>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include "Point.h"
using std::string;
using std::vector;
namespace Graph_lib
{
class Shape; // "forward declare" Shape
class Widget;
//------------------------------------------------------------------------------
class Window2 : public Fl_Window {
public:
// let the system pick the location:
Window2(int w, int h, const string & title);
// top left corner in xy
Window2(Point xy, int w, int h, const string & title);
virtual ~Window2() { }
int x_max() const { return w; }
int y_max() const { return h; }
void resize(int ww, int hh) { w=ww, h=hh; size(ww,hh); }
void set_label(const string& s) { copy_label(s.c_str()); }
void attach(Shape& s) { shapes.push_back(&s); }
void attach(Widget&);
void detach(Shape& s); // remove s from shapes
void detach(Widget& w); // remove w from window (deactivates callbacks)
void put_on_top(Shape& p); // put p on top of other shapes
protected:
void draw();
private:
vector<Shape*> shapes; // shapes attached to window
int w,h; // window size
void init();
};
//------------------------------------------------------------------------------
int gui_main(); // invoke GUI library's main event loop
inline int x_max() { return Fl::w(); } // width of screen in pixels
inline int y_max() { return Fl::h(); } // height of screen in pixels
} // of namespace Graph_lib
#endif // WINDOW_GUARD
/*****************************************************************/
-----------------------------here is my Window.cpp-------------------
//
// This is a GUI support code to the chapters 12-16 of the book
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//
#include <string>
#include "Window.h"
#include "Graph.h"
#include "GUI.h"
//------------------------------------------------------------------------------
namespace Graph_lib {
Window2::Window2(int ww, int hh, const string & title)
:Fl_Window(ww,hh,title.c_str()),w(ww),h(hh)
{
init();
}
//------------------------------------------------------------------------------
Window2::Window2(Point xy, int ww, int hh, const string & title)
:Fl_Window(xy.x,xy.y,ww,hh,title.c_str()),w(ww),h(hh)
{
init();
}
//------------------------------------------------------------------------------
void Window2::init()
{
resizable(this);
show();
}
//------------------------------------------------------------------------------
void Window2::draw()
{
Fl_Window::draw();
for (unsigned int i=0; i<shapes.size(); ++i) shapes[i]->draw();
}
//------------------------------------------------------------------------------
void Window2::attach(Widget& w)
{
begin(); // FTLK: begin attaching new Fl_Wigets to this window
w.attach(*this); // let the Widget create its Fl_Wigits
end(); // FTLK: stop attaching new Fl_Wigets to this window
}
//------------------------------------------------------------------------------
void Window2::detach(Widget& b)
{
b.hide();
}
//------------------------------------------------------------------------------
void Window2::detach(Shape& s)
// guess that the last attached will be first released
{
for (unsigned int i = shapes.size(); 0<i; --i)
if (shapes[i-1]==&s)
shapes.erase(shapes.begin()+(i-1));
}
//------------------------------------------------------------------------------
void Window2::put_on_top(Shape& p) {
for (int i=0; i<shapes.size(); ++i) {
if (&p==shapes[i]) {
for (++i; i<shapes.size(); ++i)
shapes[i-1] = shapes[i];
shapes[shapes.size()-1] = &p;
return;
}
}
}
//------------------------------------------------------------------------------
int gui_main()
{
return Fl::run();
}
//------------------------------------------------------------------------------
}; // of namespace Graph_lib
/****************************************************************************/
-----------------------------------------------------------------------------
unmatch?
why the first "error" in .cpp not match the third "error" in .h?
second error in cpp, not match the second "error" in .h?
for me they are "exactly" matched type.
plz help, Eric
--------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------
This question is not appropriate for the mailing list gcc@gcc.gnu.org,
which is for issues regarding the development of gcc itself. It would
be appropriate for the mailing list gcc-help@gcc.gnu.org. Please take
any followups to gcc-help. Thanks.
Unfortunately I don't know the answer to your question, as you did not
provide any source code. In the absence of other information it appears
to be a language question rather than a compiler question.
Ian
_____________________________________________________________
Luxmail.com is spam free. However, we do not throw your important emails into spam box like other defective email systems.
More information about the Gcc-help
mailing list