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

Should this compile and link?

Been looking at some code.....

#include <vector>
#include <iostream>
#include <algorithm>

template <typename T> struct A
{
struct B
{
std::vector< T > innervec;
} ;

std::vector< B > outervec;
};

template < typename T >
std::ostream & operator<< ( std::ostream & os, const typename A<T>::B &
b )
{
std::copy( b.innervec.begin(), b.innervec.end(),
std::ostream_iterator<T>( os, "\t" ) );
return os;
}

template < typename T >
std::ostream & operator<< ( std::ostream & os, const A<T>& a )
{
typedef typename A<T>::B B_t;

std::copy( a.outervec.begin(), a.outervec.end(),
std::ostream_iterator< B_t >( os, "\n" ) );
return os;
}

int main()
{
A<int> a;
A<int>::B b1;
A<int>::B b2;
b1.innervec.push_back( 11 );
b1.innervec.push_back( 12 );
b2.innervec.push_back( 21 );
b2.innervec.push_back( 22 );
a.outervec.push_back( b1 );
a.outervec.push_back( b2 );
std::cout << a;
}

Is that standard conforming?
Should it work fine as is?
My copy of MSVC 7.0 doesn't complain but Comeau's online beta says no
and fails when -tused is used.
If this is not supposed to work then why is that and what is the best
way of rewriting it?

Jul 23 '05 #1
1 1249
ru**@haydon449.plus.com wrote:
Been looking at some code.....
[...]
template < typename T >
std::ostream & operator<< ( std::ostream & os, const typename A<T>::B
'const typename A<T>::B &' is not one of the forms which the Standard
allows for template argument deduction from a function argument. So,
the compiler simply fails to deduce 'T' here, most likely.

& b )
[...]

Is that standard conforming?
I don't think so.
Should it work fine as is?
I don't think so.
My copy of MSVC 7.0 doesn't complain but Comeau's online beta says no
and fails when -tused is used.
If this is not supposed to work then why is that and what is the best
way of rewriting it?


Why should 'B' be inner to A<T>? Perhaps you should make 'B' a template
as well? The only work-around I can think of is to make 'B' a class not
nested in 'A<T>' but a separate class.

V
Jul 23 '05 #2

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

Similar topics

2
by: LP | last post by:
Hi, I have a site which runs on .Net technology. The site is already deployed and running. I need to change 1 file for some small enhancement. Please tell me, how can I compile that 1 file and...
0
by: Xiaofeng Zhang | last post by:
when I compile my project setting, there are many LINK errors. But when I compile my project under debug setting, everything is OK. How can I deal with it? The errors is followed. Linking......
5
by: PaulR | last post by:
Hi, the following gcc compile/link (in bldrtn) works fine on our Linux Servers # Set the runtime path since routines run as setuid. EXTRA_LFLAG="-Wl,-rpath,$DB2PATH/lib" # If an embedded...
9
by: Jaime | last post by:
I am using Microsoft Visual C++ and i have some projects configuration. (Configuration A, Configuration B, ..., Configuration N) I need to execute some system operation call such as copy, delete,...
6
by: Abubakar | last post by:
Hi, I'm working on a project in unmanaged c++. I was writing all (most of) my code in header files, that is, no seperation of code in header and cpp files, as usually is done in c++. I feel pretty...
10
by: Martin Jørgensen | last post by:
Hi, I got this piece of code, but I won't compile: #include <iostream> using namespace std; //////////////////////////////////////////////////////////////// struct link ...
8
by: mastermagrath | last post by:
Hi, I'm about half way through Bruce Eckels thinking in C++ Vol 1. He gives a very short example of how compiler function name decoration helps remove subtle bugs by type-safe linkage. However,...
1
by: Thureen | last post by:
I just started using the mainframe (z/OS) 2 days ago, so I am very inexperienced in it. However, I need to write c++ programs for mainframe. Right now, the other mainframe programmers have showed...
1
by: å¼ æ²ˆé¹ | last post by:
How to compile the HelloWorld of boost.asio? Maybe this is a stupid problem , but I really don't konw how to find the right way. My compile environment is WinXP, Msys , MinGw , G++ 3.4.2,...
2
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
tracyyun
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...
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.