The following code is a simplification of a example in "The C++
programming language". So, it is assumed to be STANDARD c++. But Visual
C++ 2003 complains about the function defination of get_free. Is M$
VC2003 reaaly standard in this regard?
template<class T> class MyList {
private:
struct Link {
T val;
Link *next;
};
Link* free;
Link* get_free ();
public:
void insert (T);
}
template<class T> void MyList<T>::insert (T value)
{
return;
}
template<class T>MyList<T>::Link *MyList<T>::get_free ()
{
return NULL;
} 7 2090
On 14 Dec 2004 02:01:02 -0800, zh******@gmail.com wrote: The following code is a simplification of a example in "The C++ programming language". So, it is assumed to be STANDARD c++. But Visual C++ 2003 complains about the function defination of get_free. Is M$ VC2003 reaaly standard in this regard?
template<class T> class MyList { private: struct Link { T val; Link *next; };
Link* free; Link* get_free (); public: void insert (T); }
template<class T> void MyList<T>::insert (T value) { return; }
template<class T>MyList<T>::Link *MyList<T>::get_free ()
That should be:
template<class T>
typename MyList<T>::Link *MyList<T>::get_free ()
Tom
Yes, a typename helps it.
But I think its redunant here, the compiler could have figured
it out that Link is a type name.
Thanks for helping
Tom Widmer wrote: On 14 Dec 2004 02:01:02 -0800, zh******@gmail.com wrote:
The following code is a simplification of a example in "The C++ programming language". So, it is assumed to be STANDARD c++. But
VisualC++ 2003 complains about the function defination of get_free. Is M$ VC2003 reaaly standard in this regard?
template<class T> class MyList { private: struct Link { T val; Link *next; };
Link* free; Link* get_free (); public: void insert (T); }
template<class T> void MyList<T>::insert (T value) { return; }
template<class T>MyList<T>::Link *MyList<T>::get_free ()
That should be:
template<class T> typename MyList<T>::Link *MyList<T>::get_free ()
Tom
<zh******@gmail.com> wrote... Yes, a typename helps it. But I think its redunant here, the compiler could have figured it out that Link is a type name.
(a) Please don't top-post.
(b) How could the compiler have figured it out? Don't rush with
the answer, imagine that I've defined a specialisation of your
template 'MyList' such that 'Link' is not a type any longer.
The compiler cannot automatically assume that the first thing
it sees is a type. Thanks for helping
Tom Widmer wrote: On 14 Dec 2004 02:01:02 -0800, zh******@gmail.com wrote:
>The following code is a simplification of a example in "The C++ >programming language". So, it is assumed to be STANDARD c++. But Visual >C++ 2003 complains about the function defination of get_free. Is M$ >VC2003 reaaly standard in this regard? > >template<class T> class MyList { >private: >struct Link { >T val; >Link *next; >}; > >Link* free; >Link* get_free (); >public: >void insert (T); >} > >template<class T> void MyList<T>::insert (T value) >{ >return; >} > >template<class T>MyList<T>::Link *MyList<T>::get_free ()
That should be:
template<class T> typename MyList<T>::Link *MyList<T>::get_free ()
Tom
Victor Bazarov wrote: (a) Please don't top-post.
OK
(b) How could the compiler have figured it out? Don't rush with the answer, imagine that I've defined a specialisation of your template 'MyList' such that 'Link' is not a type any longer. The compiler cannot automatically assume that the first thing it sees is a type.
You are right, g++ also complains about deprecated typename
when given the code fragment. So, the book is a little out of date and
impractical about this template thing? or, I just grabbed the wrong
book for a beginner. Thanks for helping
Tom Widmer wrote: On 14 Dec 2004 02:01:02 -0800, zh******@gmail.com wrote:
>The following code is a simplification of a example in "The C++ >programming language". So, it is assumed to be STANDARD c++. But Visual >C++ 2003 complains about the function defination of get_free. Is
M$ >VC2003 reaaly standard in this regard? > >template<class T> class MyList { >private: >struct Link { >T val; >Link *next; >}; > >Link* free; >Link* get_free (); >public: >void insert (T); >} > >template<class T> void MyList<T>::insert (T value) >{ >return; >} > >template<class T>MyList<T>::Link *MyList<T>::get_free ()
That should be:
template<class T> typename MyList<T>::Link *MyList<T>::get_free ()
Tom
On 14 Dec 2004 23:30:14 -0800, zh******@gmail.com wrote: Victor Bazarov wrote: (a) Please don't top-post.
OK
(b) How could the compiler have figured it out? Don't rush with the answer, imagine that I've defined a specialisation of your template 'MyList' such that 'Link' is not a type any longer. The compiler cannot automatically assume that the first thing it sees is a type.
You are right, g++ also complains about deprecated typename when given the code fragment. So, the book is a little out of date and impractical about this template thing? or, I just grabbed the wrong book for a beginner.
Which book is it? Certainly, Stroustrup's book is about the standard
language, so if it had the code below, its an error in the book.
A good beginners book is apparently "Accelerated C++".
Tom
Tom Widmer wrote: You are right, g++ also complains about deprecated typename when given the code fragment. So, the book is a little out of date
andimpractical about this template thing? or, I just grabbed the wrong book for a beginner. Which book is it? Certainly, Stroustrup's book is about the standard language, so if it had the code below, its an error in the book.
It's "The C++ programming language, Special 3rd edition". The code
is from page 403, $15.3 access control. I changed it a little to
illustrate the problem concisely. Have I made a mistake during that?
A good beginners book is apparently "Accelerated C++".
thanks.
Tom
<zh******@gmail.com> wrote... Tom Widmer wrote: >You are right, g++ also complains about deprecated typename >when given the code fragment. So, the book is a little out of date and >impractical about this template thing? or, I just grabbed the wrong >book for a beginner.
Which book is it? Certainly, Stroustrup's book is about the standard language, so if it had the code below, its an error in the book.
It's "The C++ programming language, Special 3rd edition". The code is from page 403, $15.3 access control. I changed it a little to illustrate the problem concisely. Have I made a mistake during that?
While TC++PL is a very good book, it just doesn't have enough room to
contain all possible things about all aspects of the language. It is
also conceivable that it contains errors or out-of-date elements. To
get the latest and most comprehensive template text, get a copy of
"C++ Templates" by Vandevoorde and Josuttis.
V This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Michael Stembera |
last post by:
I would like to use default parameters in nested templates but MS VC++
7.1 chokes on it. Does anyone know how to fix the simple example
below or if indeed it is possible?
template <int N=7>...
|
by: Jason Heyes |
last post by:
The following program does not compile. Apparantly "t" is inaccessible.
#include <iostream>
using namespace std;
template <class T> class Foo
{
T t;
public:
Foo(T t_) : t(t_) { }
|
by: Levent |
last post by:
Hi,
Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1):
#include <iostream>
template<class T, unsigned N>
struct Foo {
void func();
};
template<class T, unsigned N>
|
by: mrstephengross |
last post by:
I've got a 'Command' class whose constructor takes an instance of a
template argument T. The constructor then prints out the name of the
class T that was passed to it. When I construct the T class...
|
by: cyberdave |
last post by:
Someone please help me!
I have a template class like this:
--------------------------------------------------
template<typename T>
class List
{
public:
|
by: Hari |
last post by:
Guys please help me to solve this strange problem what Iam
getting as follows..
Trying to instantiate a global instance of a template
class as follows :-
when i build this code with debug and...
|
by: rich |
last post by:
Hi there,
I defined a class template (MyClass) and some member variables and
functions, as following:
template<class T1, class T2>
class MyClass
{
...
struct m_variable
|
by: christian |
last post by:
Hi!
I have a problem with a template function im MSVC6 the template function
is defined as:
template <__Type1, __Type2> int MyFunc(int param1, double param2)
{__Type1 var1;
__Type2 var2;
...
|
by: huili80 |
last post by:
For example, like in the following, the part commented out was
intended as partial spectialzation, but it would even compile. Is it
even legal to partially specialize a nested template class...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |