473,609 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ 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>(con st 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 1124
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>(con st 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>(con st 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>(con st 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
2442
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. i would forget overriding it but i have to do it because its a coursework. here is a simple version of the class #include <iostream> #include <string> #include <vector>
14
2654
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
2632
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 int in the map (or sets it to 1 if it doesn't already exist). I can write the function itself for a given type, but I can't figure out what template statement(s) I need to put before it to make it generalise. Stuff I've tried unsuccessfully is...
4
5071
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() { return 0;
8
3018
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 way I'm going about doing this might be a little off. I'd appreciate some help. Below is the code I have thus far but I'm not sure how to reference the user control within the foreach loop. <asp:Panel ID="pnlRosterProfile" runat="Server" />
8
2676
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 errors for missing (, or IF is not recognized, etc.
6
2889
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 My<int; What if I have a template class template <typename T, typename Uclass My ;
1
1964
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
3532
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
8053
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,...
0
8513
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 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...
0
8380
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 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...
0
6983
agi2029
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...
1
6047
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4007
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...
0
4066
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2519
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 we have to send another system
0
1374
bsmnconsultancy
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...

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.