473,484 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Is it possible to specify template as <L/2>?

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.

Oct 20 '05 #1
3 1119
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.


Compiles fine with VC 8 :)

ben
Oct 20 '05 #2
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

Oct 20 '05 #3

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;
}

Oct 21 '05 #4

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

Similar topics

2
2421
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....
14
2636
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
4
2617
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...
4
5053
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() {...
8
3000
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...
8
2667
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...
6
2877
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...
1
1955
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>
10
3509
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
0
7079
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
6949
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...
1
6809
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
7194
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...
1
4838
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...
0
3044
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...
0
3038
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1355
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 ...
1
587
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.