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
{
...
};
m_variable* MyFunc(m_variable* pv1, m_variable* pv2);
...
}
template <class T1, class T2>
MyClass<T1, T2>::m_variable* MyClass<T1, T2>::MyFunc(MyClass::m_variable*
pv1, MyClass::m_variable* pv2)
{
...
m_variable* pv;
...
return pv;
}
It compiles with VC++ v6.0, but doesn't compile with VC++ v7.0 (.Net 2003).
Anybody can give me some advice to modify the code to make it compile.
Many thanks
rich 5 1233
rich wrote: 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 { ... }; m_variable* MyFunc(m_variable* pv1, m_variable* pv2); ... }
template <class T1, class T2> MyClass<T1, T2>::m_variable* MyClass<T1, T2>::MyFunc(MyClass::m_variable* pv1, MyClass::m_variable* pv2) { ... m_variable* pv; ... return pv; }
It compiles with VC++ v6.0, but doesn't compile with VC++ v7.0 (.Net 2003). Anybody can give me some advice to modify the code to make it compile.
Please post either or both of: some actual (complete) code that doesn't
compile and the exact error(s) that you're getting from the compiler.
In all likelihood, you need to add the 'typename' keyword in a few places to
make the code legal C++ (VC6 didn't enforce that rule, VC7.1 does).
e.g.
template <class T1, class T2>
typename MyClass<T1, T2>::m_variable* MyClass<T1, T2>::MyFunc(
MyClass::m_variable* pv1,
MyClass::m_variable* pv2
)
-cd
Thanks Carl.
MyClass<T1, T2>::m_variable is the type name for return. The following is
the code and error messages.
template<class TYPE, class ARG_TYPE>
class suDynList : public CObject
{
protected:
struct suNode
{
suNode* iNext;
suNode* iPrev;
TYPE data;
};
suNode* NewNode(suNode* prev, suNode* next, ARG_TYPE& newElement);
....
template<class TYPE, class ARG_TYPE>
suDynList<TYPE, ARG_TYPE>::suNode* //line 342
suDynList<TYPE, ARG_TYPE>::NewNode(suDynList::suNode* prev,
suDynList::suNode* next,
ARG_TYPE& newElement) //line 343
{
...
c:\...\sudynlist.h(342) : warning C4346: 'suDynList<TYPE,ARG_TYPE>::suNode'
: dependent name is not a type prefix with 'typename' to indicate a type
c:\...\sudynlist.h(342) : error C2143: syntax error : missing ';' before '*'
c:\...\sudynlist.h(342) : error C2501: 'suDynList<TYPE,ARG_TYPE>::suNode' :
missing storage-class or type specifiers
c:\...\sudynlist.h(343) : error C2065: 'TYPE' : undeclared identifier
c:\...\sudynlist.h(343) : error C2065: 'ARG_TYPE' : undeclared identifier
c:\...\sudynlist.h(343) : error C2955: 'suDynList' : use of class template
requires template argument list
c:\...\sudynlist.h(120) : see declaration of 'suDynList'
c:\...\sudynlist.h(345) : error C2061: syntax error : identifier 'ARG_TYPE'
"Carl Daniel [VC++ MVP]" wrote: rich wrote: 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 { ... }; m_variable* MyFunc(m_variable* pv1, m_variable* pv2); ... }
template <class T1, class T2> MyClass<T1, T2>::m_variable* MyClass<T1, T2>::MyFunc(MyClass::m_variable* pv1, MyClass::m_variable* pv2) { ... m_variable* pv; ... return pv; }
It compiles with VC++ v6.0, but doesn't compile with VC++ v7.0 (.Net 2003). Anybody can give me some advice to modify the code to make it compile.
Please post either or both of: some actual (complete) code that doesn't compile and the exact error(s) that you're getting from the compiler.
In all likelihood, you need to add the 'typename' keyword in a few places to make the code legal C++ (VC6 didn't enforce that rule, VC7.1 does).
e.g.
template <class T1, class T2> typename MyClass<T1, T2>::m_variable* MyClass<T1, T2>::MyFunc( MyClass::m_variable* pv1, MyClass::m_variable* pv2 )
-cd
Thanks again Carl. I tried adding keyword typename in front of some of my
type names and it compiles now. Thanks a lot.
rich
"rich" wrote: Thanks Carl.
MyClass<T1, T2>::m_variable is the type name for return. The following is the code and error messages.
template<class TYPE, class ARG_TYPE> class suDynList : public CObject { protected: struct suNode { suNode* iNext; suNode* iPrev; TYPE data; }; suNode* NewNode(suNode* prev, suNode* next, ARG_TYPE& newElement); ...
template<class TYPE, class ARG_TYPE> suDynList<TYPE, ARG_TYPE>::suNode* //line 342 suDynList<TYPE, ARG_TYPE>::NewNode(suDynList::suNode* prev, suDynList::suNode* next, ARG_TYPE& newElement) //line 343 { ...
c:\...\sudynlist.h(342) : warning C4346: 'suDynList<TYPE,ARG_TYPE>::suNode' : dependent name is not a type prefix with 'typename' to indicate a type c:\...\sudynlist.h(342) : error C2143: syntax error : missing ';' before '*' c:\...\sudynlist.h(342) : error C2501: 'suDynList<TYPE,ARG_TYPE>::suNode' : missing storage-class or type specifiers c:\...\sudynlist.h(343) : error C2065: 'TYPE' : undeclared identifier c:\...\sudynlist.h(343) : error C2065: 'ARG_TYPE' : undeclared identifier c:\...\sudynlist.h(343) : error C2955: 'suDynList' : use of class template requires template argument list c:\...\sudynlist.h(120) : see declaration of 'suDynList' c:\...\sudynlist.h(345) : error C2061: syntax error : identifier 'ARG_TYPE'
"Carl Daniel [VC++ MVP]" wrote:
rich wrote: 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 { ... }; m_variable* MyFunc(m_variable* pv1, m_variable* pv2); ... }
template <class T1, class T2> MyClass<T1, T2>::m_variable* MyClass<T1, T2>::MyFunc(MyClass::m_variable* pv1, MyClass::m_variable* pv2) { ... m_variable* pv; ... return pv; }
It compiles with VC++ v6.0, but doesn't compile with VC++ v7.0 (.Net 2003). Anybody can give me some advice to modify the code to make it compile.
Please post either or both of: some actual (complete) code that doesn't compile and the exact error(s) that you're getting from the compiler.
In all likelihood, you need to add the 'typename' keyword in a few places to make the code legal C++ (VC6 didn't enforce that rule, VC7.1 does).
e.g.
template <class T1, class T2> typename MyClass<T1, T2>::m_variable* MyClass<T1, T2>::MyFunc( MyClass::m_variable* pv1, MyClass::m_variable* pv2 )
-cd
rich wrote: Thanks again Carl. I tried adding keyword typename in front of some of my type names and it compiles now. Thanks a lot.
rich
"rich" wrote:
Thanks Carl.
MyClass<T1, T2>::m_variable is the type name for return. The following is the code and error messages.
template<class TYPE, class ARG_TYPE> class suDynList : public CObject { protected: struct suNode { suNode* iNext; suNode* iPrev; TYPE data; }; suNode* NewNode(suNode* prev, suNode* next, ARG_TYPE& newElement); ...
template<class TYPE, class ARG_TYPE> suDynList<TYPE, ARG_TYPE>::suNode* //line 342 suDynList<TYPE, ARG_TYPE>::NewNode(suDynList::suNode* prev, suDynList::suNode* next, ARG_TYPE& newElement) //line 343 { ...
c:\...\sudynlist.h(342) : warning C4346: 'suDynList<TYPE,ARG_TYPE>::suNode' : dependent name is not a type prefix with 'typename' to indicate a type c:\...\sudynlist.h(342) : error C2143: syntax error : missing ';' before '*' c:\...\sudynlist.h(342) : error C2501: 'suDynList<TYPE,ARG_TYPE>::suNode' : missing storage-class or type specifiers c:\...\sudynlist.h(343) : error C2065: 'TYPE' : undeclared identifier c:\...\sudynlist.h(343) : error C2065: 'ARG_TYPE' : undeclared identifier c:\...\sudynlist.h(343) : error C2955: 'suDynList' : use of class template requires template argument list c:\...\sudynlist.h(120) : see declaration of 'suDynList' c:\...\sudynlist.h(345) : error C2061: syntax error : identifier 'ARG_TYPE'
"Carl Daniel [VC++ MVP]" wrote:
rich wrote:
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 { ... }; m_variable* MyFunc(m_variable* pv1, m_variable* pv2); ... }
template <class T1, class T2> MyClass<T1, T2>::m_variable* MyClass<T1, T2>::MyFunc(MyClass::m_variable* pv1, MyClass::m_variable* pv2) { ... m_variable* pv; ... return pv; }
It compiles with VC++ v6.0, but doesn't compile with VC++ v7.0 (.Net 2003). Anybody can give me some advice to modify the code to make it compile.
Please post either or both of: some actual (complete) code that doesn't compile and the exact error(s) that you're getting from the compiler.
In all likelihood, you need to add the 'typename' keyword in a few places to make the code legal C++ (VC6 didn't enforce that rule, VC7.1 does).
e.g.
template <class T1, class T2> typename MyClass<T1, T2>::m_variable* MyClass<T1, T2>::MyFunc( MyClass::m_variable* pv1, MyClass::m_variable* pv2 )
-cd
OK, I do have to ask: Can you suggest how we could make the compiler
error message more clear? We worked very hard here to have the compiler
give a really accurate diagnostic, but in practice it still fails to
help many developers. Any suggestions on how to improve it are very welcome.
Thanks!
Ronald Laeremans
Visual C++ team
Ronald Laeremans [MSFT] <ro*****@online.microsoft.com> wrote: [...]c:\...\sudynlist.h(342) : warning C4346: 'suDynList<TYPE,ARG_TYPE>::suNode' : dependent name is not a type prefix with 'typename' to indicate a type [...]
OK, I do have to ask: Can you suggest how we could make the compiler error message more clear? [...]
I doubt that you could get much better than saying
"prefix with 'typename' to indicate a type". IMHO
the reason this still gets asked here so often is
that many VC-only developers (do as the VC team did
for many years and) don't care much for the C++ std.
They simply never heard of 'typename', they never
bothered to really learn templates, and never read
a general C++ book. It's only 2 years that you have
a more or less decent compiler regarding templates
(and thus show a different attitude towards std C++)
-- it will take a while for your customers to catch
up. (I don't see it as an incident that many of
those who answer such questions here seem to have
regular exposure to other compilers.)
I expect an even bigger amount of FAQs swamping this
newsgroup should you ever get around to implement
std conforming lookup rules. Porting template code
checked using VC7.1 to other compilers (many of
which do implement proper lookup) is a PITA due to
this.
Ronald Laeremans
Schobi
-- Sp******@gmx.de is never read
I'm Schobi at suespammers dot org
"Coming back to where you started is not the same as never leaving"
Terry Pratchett This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sebastian Faust |
last post by:
Hi,
I have 4 questions related to templates.
I wanna do something like the following:
template<typename T>
class Template
{
public:
Template_Test<T>()
|
by: Oplec |
last post by:
Hi,
I'm learning C++ as a hobby using The C++ Programming Language : Special
Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that
deal with templates. Exercise 13.9 asks for me...
|
by: Hamilton Woods |
last post by:
Diehards,
I developed a template matrix class back around 1992 using Borland C++ 4.5
(ancestor of C++ Builder) and haven't touched it until a few days ago. I
pulled it from the freezer and...
|
by: zfareed |
last post by:
#include <iostream>
#include <fstream>
using namespace std;
template<class ItemType>
class SortedList
{
private:
|
by: Dan Smithers |
last post by:
I want to write my own class derived from the ostream class.
I have been getting errors with my templates:
First, I get an error writing a nested template. If I leave the function
definition...
| |
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: 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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |