I tried the following in MSVC7.1 but was told "unable to deduce
template parameter".
template <int L, int M, int T> class Quantity;
template <int L, int M, int T> Quantity<L/2,M/2,T/2> sqrt(const
Quantity<L,M,T>& q);
template <int L, int M, int T>
class Quantity
{public:...
friend Quantity<L/2,M/2,T/2> sqrt<L,M,T>(const Quantity<L,M,T>& q);
};
template <int L,int M, int T>
Quantity<L/2,M/2,T/2> sqrt(const Quantity<L,M,T>& q)
{
Quantity<L/2,M/2,T/2> q1;
return q1;
};
That's for a unit system operation.
I succeed with return type like <L1+L2,M1+M2,T1+T2> (For multiply).
Also for pow, I failed. 3 1119
Atlas wrote: I tried the following in MSVC7.1 but was told "unable to deduce template parameter". template <int L, int M, int T> class Quantity; template <int L, int M, int T> Quantity<L/2,M/2,T/2> sqrt(const Quantity<L,M,T>& q); template <int L, int M, int T> class Quantity {public:... friend Quantity<L/2,M/2,T/2> sqrt<L,M,T>(const Quantity<L,M,T>& q); }; template <int L,int M, int T> Quantity<L/2,M/2,T/2> sqrt(const Quantity<L,M,T>& q) { Quantity<L/2,M/2,T/2> q1; return q1; }; That's for a unit system operation. I succeed with return type like <L1+L2,M1+M2,T1+T2> (For multiply). Also for pow, I failed.
Compiles fine with VC 8 :)
ben
Atlas wrote: I tried the following in MSVC7.1 but was told "unable to deduce template parameter". template <int L, int M, int T> class Quantity; template <int L, int M, int T> Quantity<L/2,M/2,T/2> sqrt(const Quantity<L,M,T>& q); template <int L, int M, int T> class Quantity {public:... friend Quantity<L/2,M/2,T/2> sqrt<L,M,T>(const Quantity<L,M,T>& q); }; template <int L,int M, int T> Quantity<L/2,M/2,T/2> sqrt(const Quantity<L,M,T>& q) { Quantity<L/2,M/2,T/2> q1; return q1; }; That's for a unit system operation. I succeed with return type like <L1+L2,M1+M2,T1+T2> (For multiply). Also for pow, I failed.
L, M, and T in this case are constants, not integer variables. So the
compiler *should* be able to evaluate things like L/2. Apparently
yours does not, so the best solution is to get a better one.
FWIW, Comeau's online C++ compiler accepted the code after I removed
the extra semicolon and the ellipsis.
Kristo
Kristo wrote: Atlas wrote: I tried the following in MSVC7.1 but was told "unable to deduce template parameter". template <int L, int M, int T> class Quantity; template <int L, int M, int T> Quantity<L/2,M/2,T/2> sqrt(const Quantity<L,M,T>& q); template <int L, int M, int T> class Quantity {public:... friend Quantity<L/2,M/2,T/2> sqrt<L,M,T>(const Quantity<L,M,T>& q); }; template <int L,int M, int T> Quantity<L/2,M/2,T/2> sqrt(const Quantity<L,M,T>& q) { Quantity<L/2,M/2,T/2> q1; return q1; }; That's for a unit system operation. I succeed with return type like <L1+L2,M1+M2,T1+T2> (For multiply). Also for pow, I failed.
L, M, and T in this case are constants, not integer variables. So the compiler *should* be able to evaluate things like L/2. Apparently yours does not, so the best solution is to get a better one.
FWIW, Comeau's online C++ compiler accepted the code after I removed the extra semicolon and the ellipsis.
Kristo
Thanks you all. To use VC2003, I modified my codes. Simply put,
eliminate the friend declaration. In this way it works, but I have to
implement a lot of seter/geter of my class members. The example codes
listed.
Maybe VC has some special requirements on template friend?
-------
template <int L, int M, int T>
class Quantity
{
public:
};
template <int L,int M, int T>
Quantity<L/2,M/2,T/2> sqrt(const Quantity<L,M,T>& q)
{
Quantity<L/2,M/2,T/2> q1;
return q1;
}
int main()
{
Quantity<0,0,2> q;
Quantity<0,0,1> w = sqrt(q);
return 0;
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: franklini |
last post by:
hello people i. can anybody help me, i dont know what is wrong with
this class. it has something to do with the me trying to override the
input output stream. if i dont override it, it works fine....
|
by: LumisROB |
last post by:
Is it possible to create matrixes with vector <vector <double >> ? If
it is possible which is the element m23 ?
You excuse but I am not an expert
Thanks
ROB
|
by: Stuart Moore |
last post by:
Hi, I'm quite new to templates and I seem to be getting myself messed
up. I want to write a function that takes a map<T, int> and a set<T>,
iterates over the set, and increments the corresponding...
|
by: Gary li |
last post by:
Hi, all
I find "template template" class cann't been compiled in VC6 but can ok
in Redhat9. I write a test program like as:
template< template<class> class T>
class A
{
};
int main()
{...
|
by: fernandezr |
last post by:
I would like to use a user control as a template inside a repeater.
Some of the fields in the control should be hidden depending on whether
or not there is data. I'm still a ASP .Net newbie so the...
| |
by: Mike |
last post by:
Is it possible to do this in the HTML of the aspx page?
<#% if Eval("Name") != null %>
write something here
<#% else %>
show message for missing name
<#% end if %>
when I try this I get...
|
by: year1943 |
last post by:
For
template <typename Tclass My ;
I can define partial spec-ns somewhat like
template <typename Tclass My<T*; or
template <typename Tclass My<Another<T ;
And full spec-n, say
template <class...
|
by: DR |
last post by:
What is the fastest possible xsl style sheet to add another <boxnode under
<boxes?
<foo>
<car></car>
<boxes>
<box id="234" />
<box id="75" />
</boxes>
</foo>
|
by: jason.cipriani |
last post by:
Is there any difference between declaring a template parameter as a
"typename" or a "class"? E.g.
template <class TT f() { }
template <typename TT g() { }
Thanks,
Jason
|
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,...
|
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...
| |
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...
|
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...
|
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: 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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |