473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Template not found

Hi,

why do icc and g++ not find the template in the following code?
template <typename T>
struct Wrap {
struct Inner {
};
};

template<typename T>
void func(typename Wrap<T>::Inner const & n)
{

}

int main() {
func( Wrap<int>::Inner() );
}

Or is the code wrong?

Greets,
Christoph Bartoschek
Jul 22 '05 #1
9 1613
Christoph Bartoschek wrote:
Hi,

why do icc and g++ not find the template in the following code?
template <typename T>
struct Wrap {
struct Inner {
This one ought to be static to be able to be
accessed from the outer class.

struct Wrap {
static struct Inner {
};
};

};
};

template<typename T>
void func(typename Wrap<T>::Inner const & n)
{

}

int main() {
func( Wrap<int>::Inner() );
}


func is a template function which is not a function by
itself. You need to qualify it with the relevant type,
to create a function object and invoke it.

func<int>( Wrap<int>::Inner() );

int because, you are passing it a Wrap<int> to it anyway.

--
Karthik.
Jul 22 '05 #2
Christoph Bartoschek wrote in news:uo************@ID-80222.user.uni-
berlin.de in comp.lang.c++:
Hi,

why do icc and g++ not find the template in the following code?
template <typename T>
struct Wrap {
struct Inner {
};
};

template<typename T>
void func(typename Wrap<T>::Inner const & n)
{

}
Imagine:

template < typename T >
struct wrap< T * >
{
typedef int Inner;
};
You could try to call func< int * > like:

func( wrap< int * >::Inner() );
But what the compiler see's is

func( int() );

And it can't deduce T from that as any T would do.

The above declaration for func<>() is fine except T is non-deducable,
you have to specify T explicitly when calling:

int main() {
func( Wrap<int>::Inner() );
func< int >( Wrap<int>::Inner() );
}

Or is the code wrong?


The call int main() is "wrong".

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #3
Christoph Bartoschek wrote:
Hi,

why do icc and g++ not find the template in the following code?
template <typename T>
struct Wrap {
struct Inner {
};
};

template<typename T>
void func(typename Wrap<T>::Inner const & n)
{

}

int main() {
func( Wrap<int>::Inner() );
}


And yes, you got to return a value from the main function.

#include <cstdlib>

int main() {
..
return EXIT_SUCCESS; // EXIT_FAILURE if things go bad.
}
Jul 22 '05 #4
Karthik Kumar wrote in news:41ca093d@darkstar in comp.lang.c++:
Christoph Bartoschek wrote:
Hi,

why do icc and g++ not find the template in the following code?
template <typename T>
struct Wrap {
struct Inner {
This one ought to be static to be able to be
accessed from the outer class.

struct Wrap {
static struct Inner {
};
};

Since an object *isn't* being declared the is no reason for
static, and its IIRC illegal (IOW an error).

};
};

template<typename T>
void func(typename Wrap<T>::Inner const & n)
{

}

int main() {
func( Wrap<int>::Inner() );
}
func is a template function which is not a function by
itself.


You are no doubt try to say somthing, but I can't grep it.
You need to qualify it with the relevant type,
to create a function object and invoke it.

func<int>( Wrap<int>::Inner() );
Correct.

int because, you are passing it a Wrap<int> to it anyway.


The is no Wrap<int> being passed anywhere.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #5
Karthik Kumar wrote in news:41ca0c25$1@darkstar in comp.lang.c++:
And yes, you got to return a value from the main function.

#include <cstdlib>

int main() {
..
return EXIT_SUCCESS; // EXIT_FAILURE if things go bad.
}


No you don't main() has an exception, if main has no return statEment
its as if you put return 0; as the last statment, which is itself
equivalent to return EXIT_SUCCESS;

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #6
Rob Williscroft wrote:
Karthik Kumar wrote in news:41ca093d@darkstar in comp.lang.c++:

Christoph Bartoschek wrote:
Hi,

why do icc and g++ not find the template in the following code?
template <typename T>
struct Wrap {
struct Inner {


This one ought to be static to be able to be
accessed from the outer class.

struct Wrap {
static struct Inner {
};
};


Since an object *isn't* being declared the is no reason for
static, and its IIRC illegal (IOW an error).
};
};

template<typename T>
void func(typename Wrap<T>::Inner const & n)
{

}

int main() {
func( Wrap<int>::Inner() );
}


func is a template function which is not a function by
itself.

You are no doubt try to say somthing, but I can't grep it.


Sorry. I did not word it correctly. I meant to say -
you cannot invoke a template function without qualifying it
with appropriate types.
Jul 22 '05 #7
Rob Williscroft wrote:
Imagine:

template < typename T >
struct wrap< T * >
{
typedef int Inner;
};
You could try to call func< int * > like:

func( wrap< int * >::Inner() );
But what the compiler see's is

func( int() );

And it can't deduce T from that as any T would do.

The above declaration for func<>() is fine except T is non-deducable,
you have to specify T explicitly when calling:


Ok, however this are bad news, because the original func was:

template <typename T>
std::ostream & operator<<(std::ostream &, Wrap<T>::Inner const &);

It does not look good, when one has to specifiy T explicitly in:

std::cout << Wrap<int>::Inner() << std::endl;
However can you give me some references to the standard where I can look up,
that the code is wrong?

Greets,

Christoph Bartoschek
Jul 22 '05 #8
Karthik Kumar wrote in news:41ca1525$1@darkstar in comp.lang.c++:
int main() {
func( Wrap<int>::Inner() );
}

func is a template function which is not a function by
itself.

You are no doubt try to say somthing, but I can't grep it.


Sorry. I did not word it correctly. I meant to say -
you cannot invoke a template function without qualifying it
with appropriate types.


Well there are cases where that is true, but in general template
paramiter types are deduced fine, without any need for qualification:

template < typename T >
T f( T t )
{
return t + 2;
}

int main()
{
int i = f(2)
double d = f(2.2);
}

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #9
Christoph Bartoschek wrote in
news:up************@ID-80222.user.uni-berlin.de in comp.lang.c++:
Ok, however this are bad news, because the original func was:

template <typename T>
std::ostream & operator<<(std::ostream &, Wrap<T>::Inner const &);

It does not look good, when one has to specifiy T explicitly in:

std::cout << Wrap<int>::Inner() << std::endl;
However can you give me some references to the standard where I can
look up, that the code is wrong?


Just start by reading the section on templates, I've read that section
all the way through several times now, and I still don't get all of it.

I say this as that is what I would have to do in order to give the
references you've requested. It wouldn't do me any harm to read it
again, but the same is possibly true for you too :).

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Thomas Heller | last post by:
I need to convert C preprocessor definitions into python code. The definitions are dumped out of gccxml (see http://www.gccxml.org) , running over the windows header files (for example). This...
14
by: Bart Samwel | last post by:
Hi everybody, I would really like some help explaining this apparent discrepancy, because I really don't get it. Here is the snippet: void foo(int&); void foo(int const&); ...
2
by: CW | last post by:
In an earlier thread, I was asking for help on "Invalid attempt to FieldCount when reader is closed" error when I was using a dataset rather than a datareader to bind to a datagrid. After...
5
by: henkoo | last post by:
i want to explicit instantiate a member function of a class template, and got some error, can anyone give some advice to correct it? 3x complier: g++ 3.2 #include <iostream> #include...
1
by: Kai-Uwe Bux | last post by:
Hi folks, I would like to know which clause of the standard rules out this: template < typename eval > struct recursive_template { typedef typename eval::enum_type Enum;
45
by: charles.lobo | last post by:
Hi, I have recently begun using templates in C++ and have found it to be quite useful. However, hearing stories of code bloat and assorted problems I decided to write a couple of small programs...
8
by: hurcan solter | last post by:
given the code snippet; template<typename T> void foo(T,T){} template<typename T1,typename T2> void foo(T1*,T2*){} int main( ) {
4
by: Alan Woodland | last post by:
I've been trying out more template metaprogramming ideas with typelists (mostly for personal learning, I'm aware boost most probably provides this facility already), and I've run into this small...
9
by: neildferguson | last post by:
I am using templates with a little project I am working on. My compiler (GCC) is finding a particular construct ambiguous. Can anyone suggest something I might change in the declaration of class...
2
by: .rhavin grobert | last post by:
hello;-) i have that following little template that defines some type of vector. it works with structs and i want to use it also for simple pointers. the problem is, in following function......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
0
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.