Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++ - Problem with a template
Trying out a simple template in order to learn them and I have encountered a problem. If you put these 2 files in the same directory and do "dmc -cpp -I. stackDemo.cpp" you will get a working stackDemo executable. But if you try "dmc -cpp -I. stackDemo.cpp -DSEPARATE" you get stack.h(88) : Error: 'operator <<' is not a member of 'stack<int >' --- errorlevel 1 instead. For some reason I can't get things to compile if the definition of << is out of the class declaration. What I am doing wrong? Also, I would like to know if the declarations for the copy constructor and assignment operator are correct: stack(const stack &s); stack & operator=(const stack &s); Should I be using stack or stack<T> for the return and argument types? All of the examples that I have seen in books are for member functions like void push(const T &value); T pop(); or constructors where this issue does not arise. Any help would be appreciated. Thanks, Edward Sep 28 2006
Edward A. Waugh wrote:Trying out a simple template in order to learn them and I have encountered a problem. If you put these 2 files in the same directory and do "dmc -cpp -I. stackDemo.cpp" you will get a working stackDemo executable. But if you try "dmc -cpp -I. stackDemo.cpp -DSEPARATE" you get stack.h(88) : Error: 'operator <<' is not a member of 'stack<int >' --- errorlevel 1 instead. For some reason I can't get things to compile if the definition of << is out of the class declaration. What I am doing wrong? Sep 30 2006
As requested I have simplified the code - please see the attached files - which yield the error: C:\Upload> dmcpp problem.cpp problem.h(25) : Error: 'operator <<' is not a member of 'stack<int >' --- errorlevel 1 What is wrong? Thanks, Edward Oct 01 2006
Edward Waugh wrote:As requested I have simplified the code - please see the attached files - which yield the error: C:\Upload> dmcpp problem.cpp problem.h(25) : Error: 'operator <<' is not a member of 'stack<int >' --- errorlevel 1 What is wrong? Oct 01 2006
But isn't the << operator supposed to be declared as a friend of the class that its implementing I/O for? It works if I define it, as a friend, within the class declaration so from now on that is what I am going to do. - Edward Oct 03 2006
Edward A. Waugh wrote:But isn't the << operator supposed to be declared as a friend of the class that its implementing I/O for? Oct 03 2006
|