Hello,
Consider the following short code snippet:
template <class TType1> class CA
{
public:
friend ostream& operator<<( ostream &o, CA<TType1> a )
{
// do something reasonable here...
return o;
}
};
template <class TType1> class CB
{
public:
CB()
{
CA<int> Data;
cout << Data << endl;
}
};
int main( int argc, char *argv[] )
{
CB<int> a;
return 1;
}
Can someone explain why MSVC 6.0 informs me that:
error C2679: binary '<<' : no operator defined which takes a right-hand
operand of type 'class CA<int>' (or there is no acceptable conversion)
It appears that the construction of the template member functions isn't
occuring as I would expect. I admit I'm not a compiler expert. What's the
skinny here and what's the best solution? I've found a few solutions but
they all seem convoluted - basically I instance a CA<int> in various other
places or I have CB inherit from CA.
Thanks,
Mike 1 1327
"Michael W. Hicks" <mh*****@speake asy.net> wrote... Consider the following short code snippet:
template <class TType1> class CA { public: friend ostream& operator<<( ostream &o, CA<TType1> a ) { // do something reasonable here... return o; } };
template <class TType1> class CB { public: CB() { CA<int> Data; cout << Data << endl; } };
int main( int argc, char *argv[] ) { CB<int> a; return 1; }
Can someone explain why MSVC 6.0 informs me that:
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class CA<int>' (or there is no acceptable conversion)
It appears that the construction of the template member functions isn't occuring as I would expect. I admit I'm not a compiler expert. What's the skinny here and what's the best solution? I've found a few solutions but they all seem convoluted - basically I instance a CA<int> in various other places or I have CB inherit from CA.
You should probably declare the function before trying to define it.
Declaring it (and you want it a template) requires to put 'template'
there. That would give your compiler a notion that the function is
actually a template.
template<class T> class CA;
template<class T> ostream& operator<<(ostr eam&, CA<T> const&);
....
Victor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Elven |
last post by:
Hi!
I was trying to find the solution to this problem, but I don't think I
could quite come up with the correct keywords to find it, since I'm
pretty sure it's been asked before. In short, here's the situation
(ignore missing namespaces, etc, since I'm not cut-pasting this..)
// a.h
template <class B>
|
by: Grey Plastic |
last post by:
I have several classes that all keep track of static data. However,
the manner that they keep track of static data is identical, and so
I'm using the template<class Child> class Parent { ... }; idiom (don't
know the name of it, if there is one). The problem is that I don't
want any of my classes to have public constructors. They should be
created by a static member function.
This is what I want to do, save for the fact that this...
|
by: nikola |
last post by:
Hi all,
I was working with a simple function template to find the min of two values.
But since I would like the two values to be different (type) I dont know
what kind of value (type) it will return. I tried to write something like
this:
template <class Type1, class Type2, class Type3>
Type3 findMin(Type1 x, Type2 y){
return (x < y) ? x : y;
|
by: JT |
last post by:
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
|
by: vpadial |
last post by:
Hello,
I want to build a library to help exporting c++ functions to a
scripting languagge. The scripting language provides a function to
register functions like:
ANY f0()
ANY f1(ANY)
ANY f2(ANY, ANY)
ANY f3(ANY, ANY, ANY)
| |
by: Johan |
last post by:
Hi
Can somebody explain to me why I get this warning message and how I
can solve this warning message.
Thanks a lot
Johan
In member function `void
|
by: christopher diggins |
last post by:
It appears that the following is not considered a class:
template<typename T>
class C { };
?
So officially is this considered: a class, a template, a class template, or
a template class? I always thought of it as a parameterized class. What
would the rationale be for not considering it as just a 'class'?
|
by: Erik Wikström |
last post by:
I've been trying for a while now to understand how template template
parameters work. But I just can't wrap my head around it and was hoping
that someone might help me. As best I can figure the code should look
something like this:
template<template<typename S> typename T>
struct element_traits {
typedef S type;
};
|
by: SoilMan |
last post by:
Consider the following:
class xyz
{
public:
template <typename T>
void foo(T x)
{
cout << "foo<T> " << x << endl;
}
|
by: Jason |
last post by:
/*
I have never use template before, so bear with me.
Here is what I am trying to do:
I declare an abstract base class MatrixInterface with template to
define an interface for all my subsequent Matrix class. In
MatrixInterface class, I overloaded the << operator by calling a pure
virtual function PrintDebugMessage(ostream &os); then I can implement
the function on individual Matrix classes later.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |