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

Templates and user defined conversion operator

Hi to everybody, can someone help me?

This compiles in C++:

struct Foo
{
// Function template bar
template <class T>
void bar (T t){}
// Function bar that forwards to bar<T> [with T=int]
void bar (int i){fun<int>(i);}
};

But what if you consider in place of bar the user defined conversion
operator?
How can I express in a correct way the next chunk of code?

This doesn't compile:

struct Foo
{
// Template user defined conversion
template <class T>
operator T (){}
// I would like to forward to operator T [with T=int]
operator int (){operator int<int>();}
};

Is there a way to distinguish between operaror int and operator T [with
T=int]?

Thank you in advance,
Regards Daniele

Jul 23 '05 #1
0 1161

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

Similar topics

1
by: Bo Xu | last post by:
Object of Combination By Bo Xu Introduction A combination of n things, taken s at a time, often referred as an s-combination out of n, is a way to select a subset of size s from a given set of...
4
by: Magnus Jonneryd | last post by:
I want to be able to define a super class that defines some basic functionality and also some helpers that define, mainly, arithmetic operations, but I've been having some trouble. The following...
1
by: Patric_J | last post by:
Why can't the as operator perform user-defined conversions? Is it a C# problem or with MSIL? I can't see any reasons why the compiler should'nt be able to use a user-defined conversion operator....
2
by: allan.mcrae | last post by:
I am having trouble with overloading the += operator when template parameters are used. I have a class holding an array (called "derived" in the following example) which derives from a base class...
8
by: sagi.perel | last post by:
I have tried to compile the following code on Win & Unix. Doesn't work on either. <----- CODE -----> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <vector> #include...
3
by: Wayne | last post by:
Are user-defined conversions chosen at compile time, or are there ways to make sure that they are chosen at run-time, based on the actual type of the object? Here is a simplified example of what...
3
by: Szabolcs | last post by:
Consider the attached example. When I try to compile it (with g++ 4.1.2), I get the error message error: no matching function for call to 'fun(A<int>&)' However, if I do not use templates, it...
3
by: hurcan solter | last post by:
I have an host class that holds fundamental types template<typename T> struct Generic{ Generic(T val= T()):mval(val){} operator T(){return mval;) T mval; }
3
by: Belebele | last post by:
Suppose that I have a class that has a user-defined conversion to std::string, and I would like to compare objects of that class to "strings" (e.g. literals, std::strings): class InUpperCase {...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
marktang
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,...
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...

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.