I have a compiler error when using a non-dependent type declared in a
template, if I use the type in function definitions. I think it is a
parsing issues related to confusion with a typename. Below I have a
simple example. Is there another solution I should be using instead of
declaring the type outside of the template?
Thanks,
JT
For a class, this works, and the typedef is available in the function
definition...
class Test
{
typedef int myIntTypedef;
myIntTypedef funct();
};
Test::myIntTypedef Test::funct()
{
return 0;
}
For a template, however, the above does not work, because (I think) the
type is not available. The compiler (VC++7.1) suggests I use typename
for the type, which is not correct in this case.
template <class T>
class Test2
{
typedef int myIntTypedef;
myIntTypedef funct();
};
template <class T>
Test2<T>::myIntTypedef Test2<T>::funct() // error "dependent name is
not a type"
{
return 0;
}
If I define the type outside of the template, it will work...
typedef int myIntTypedef;
template <class T>
class Test3
{
myIntTypedef funct();
};
template <class T>
Test3<T>::myIntTypedef Test3<T>::funct()
{
return 0;
} 2 1180
JT wrote: I have a compiler error when using a non-dependent type declared in a template, if I use the type in function definitions. I think it is a parsing issues related to confusion with a typename. Below I have a simple example. Is there another solution I should be using instead of declaring the type outside of the template?
Thanks, JT
For a class, this works, and the typedef is available in the function definition...
class Test { typedef int myIntTypedef; myIntTypedef funct(); };
Test::myIntTypedef Test::funct() { return 0; }
For a template, however, the above does not work, because (I think) the type is not available. The compiler (VC++7.1) suggests I use typename for the type, which is not correct in this case.
How do _you_ know that it's not correct? If I define a specialisation
of your Test2 template like this:
template<> class Test2<char>
{
static std::string myIntTypedef;
};
then 'myIntTypedef' will NOT be a type-id for the Test2<char> but will
still be a type-id for any other Test2 instantiation. That means that
'myIntTypedef' _is_ type-dependent. template <class T> class Test2 { typedef int myIntTypedef; myIntTypedef funct(); };
template <class T> Test2<T>::myIntTypedef Test2<T>::funct() // error "dependent name is not a type"
This should be
template<class T>
typename Test2<T>::myIntTypedef Test2<T>::funct()
{ return 0; }
If I define the type outside of the template, it will work...
typedef int myIntTypedef;
template <class T> class Test3 { myIntTypedef funct(); };
template <class T> Test3<T>::myIntTypedef Test3<T>::funct() { return 0; }
"JT" <sp*******@bogus.com> wrote in message
news:41***************@bogus.com... I have a compiler error when using a non-dependent type declared in a template, if I use the type in function definitions. I think it is a parsing issues related to confusion with a typename. Below I have a simple example. Is there another solution I should be using instead of declaring the type outside of the template?
Thanks, JT
For a class, this works, and the typedef is available in the function definition...
class Test { typedef int myIntTypedef; myIntTypedef funct(); };
Test::myIntTypedef Test::funct() { return 0; }
For a template, however, the above does not work, because (I think) the type is not available. The compiler (VC++7.1) suggests I use typename for the type, which is not correct in this case.
Not sure why you think that.
template <class T> class Test2 { typedef int myIntTypedef; myIntTypedef funct(); };
template <class T> Test2<T>::myIntTypedef Test2<T>::funct() // error "dependent name is not a type" { return 0; }
This compiles fine for me.
template <class T>
typename Test2<T>::myIntTypedef Test2<T>::funct()
{
return 0;
}
Compiler error message was correct as far as I can see.
john This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Wolfgang Lipp |
last post by:
<annotation>
the first eleven contributions in this thread started
as an off-list email discussion; i have posted them
here with the consent of their authors. -- _w.lipp
</annotation>
From:...
|
by: Philip |
last post by:
Hi,
I am trying to output certain nodes inside another. I have an xml
template with field definitions for a form, and this includes
textfields, labels, checkboxes etc plus fieldssets. I defined...
|
by: Jim West |
last post by:
I have a template class (for numerical processing) that was originally
written for real data that I need to extend to complex data, and I am
running into a problem. The current version (greatly...
|
by: Code4u |
last post by:
I need to design data storage classes and operators for an image
processing system that must support a range of basic data types of
different lengths i.e. float, int, char, double. I have a...
|
by: mathieu |
last post by:
Hello,
I did read the FAQ on template(*), since I could not find an answer
to my current issue I am posting here. I have tried to summarize my
issue in the following code (**).
Basically I am...
|
by: shapper |
last post by:
Hello,
I am for days trying to apply a XSL transformation to a XML file and
display the result in a the browser. I am using Asp.Net 2.0.
Please, could someone post just a simple code example,...
|
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted...
|
by: magicofureyes |
last post by:
Hello Guys im a just a new user and i dnt knw much abt Xml i want to upload a new template in Blogger so got some free coding but when i save this code in Blogger template it say
'''' Your...
|
by: Gaiason |
last post by:
Hi XML/XSLT masters and gurus,
I am a newbie in XML/XSLT and have been reading up XML/XSLT in order to convert a XML generated from a OCR engine to another format of XML. I am truly stuck at this...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
| |