473,385 Members | 1,317 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,385 software developers and data experts.

Template matching with inner classes

Hello, I'm having difficulty getting template matching to work with
inner classes. I've tried to look up the way to fix this in my
references, but I haven't found the fix yet. When I try to compile the
program below (g++ 3.3/4.0), I get

test.cpp: In function `int main()':
test.cpp:19: error: no match for 'operator<<' in 'std::cout << x'

Does anyone know what I'm doing wrong? Thanks!

Mark
#include <iostream>

template <typename T>
struct outer {
struct inner {
T z;
};
};

template <typename T>
std::ostream& operator<<(std::ostream& out,
typename outer<T>::inner& i) {
out << i;
return out;
}

int main(void) {
outer<int>::inner x;
std::cout << x;
return EXIT_SUCCESS;
}

Jul 23 '05 #1
1 1892
Mark Paskin wrote:
Hello, I'm having difficulty getting template matching to work with
inner classes. I've tried to look up the way to fix this in my
references, but I haven't found the fix yet. When I try to compile the
program below (g++ 3.3/4.0), I get

test.cpp: In function `int main()':
test.cpp:19: error: no match for 'operator<<' in 'std::cout << x'

Does anyone know what I'm doing wrong? Thanks!

Mark
#include <iostream>

template <typename T>
struct outer {
struct inner {
T z;
};
};

template <typename T>
std::ostream& operator<<(std::ostream& out,
typename outer<T>::inner& i) {
out << i;
return out;
}

int main(void) {
outer<int>::inner x;
std::cout << x;
return EXIT_SUCCESS;
}


Literally, less than a week ago, the same question was answered here.
Please, before posting again, take time to read the FAQ and the archives.

The program is invalid because T in operator<< cannot be deduced as 'int'.
The context outer<T>::inner is not one for which the Standard requires the
implementation to deduce T. You need to rethink your approach. Why do
you need to know T anyway?

V
Jul 23 '05 #2

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

Similar topics

1
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...
1
by: Joachim Spoerhase | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I am a XSLT-beginner and i read the XSLT-recommendation of the W3C through. But I did'nt really understand section 5.5 of the latest...
4
by: Carsten Spieß | last post by:
Hello all, i have a problem with a template constructor I reduced my code to the following (compiled with gcc 2.7.2) to show my problem: // a base class class Base{}; // two derived...
0
by: Patrick Kowalzick | last post by:
Dear all, the following code is illegeal (but compiles with MSVC 7.1): // *** illegal *** struct outer0 { template<typename inner_var> struct inner { }; template<>
1
by: jn | last post by:
Hi everyone, I was trying to implement a design when I've found what seems a limitation of standard C++. I can't specialize an inner class in this way: template <class ARG> template <>...
6
by: Neal | last post by:
Hi All, I used an article on XSLT and XML and creating a TOC written on the MSDN CodeCorner. ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dncodecorn/html/corner042699.htm However, it did'nt...
4
by: AndrewD | last post by:
Hey C++ folks, I created this today, just for fun. You can make object allocation for any class around 6 times faster, simply by doing the following. class MyClass : public...
0
by: alexroat | last post by:
Hi, I cant understand why this code does not work. I've implemented two classes A,B that provide an array like structure (they are identical). I can convert B in A using implicit conversion, but...
6
by: abir | last post by:
i have a template as shown template<typename Sclass Indexer{}; i want to have a specialization for std::vector both const & non const version. template<typename T,typename Aclass...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
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...

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.