C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Q: C linkage and C++ template class

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
hchu@thermawave.com
Guest





PostPosted: Tue Sep 13, 2005 12:25 am    Post subject: Q: C linkage and C++ template class Reply with quote




I am using a header file provided by Portland group, which is
basically C stuff. It contains a bunch of functions that return
complex numbers. I have the option to either use std::complex class
or my own class. The reason I am trying to use my own class is due to
performance problem specifically related to the Microsoft compilers.
The odd thing is that everything compiles fine except
a bunch of warnings when I use the std::complex class. However when
I use my own complex template class, I get error messages like this:
C linkage function cannot return C++ class 'complex<T>'
under MS vc 7.1.

I looked at the <complex> header file and realized that the
std::complex classes are specialized for every type. Is that the reason
why it compiles? If it is, is there an alternative
simpler solution?

Thanks in advance for your attention.

Hanyou Chu


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Carl Barron
Guest





PostPosted: Tue Sep 13, 2005 9:08 am    Post subject: Re: Q: C linkage and C++ template class Reply with quote



In article <1126548885.053674.326370 (AT) g47g2000cwa (DOT) googlegroups.com>,
<hchu (AT) thermawave (DOT) com> wrote:

Quote:
I am using a header file provided by Portland group, which is
basically C stuff. It contains a bunch of functions that return
complex numbers. I have the option to either use std::complex class
or my own class. The reason I am trying to use my own class is due to
performance problem specifically related to the Microsoft compilers.
The odd thing is that everything compiles fine except
a bunch of warnings when I use the std::complex class. However when
I use my own complex template class, I get error messages like this:
C linkage function cannot return C++ class 'complex<T>'
under MS vc 7.1.

I looked at the <complex> header file and realized that the
std::complex classes are specialized for every type. Is that the reason
why it compiles? If it is, is there an alternative
simpler solution?

Thanks in advance for your attention.

Hanyou Chu

If you are going to write your own complex number class

I can suggest inheriting privately from the Portland struct.
this will give your complex class easy conversion to the
Portland struct which is a pod and the compiler should copy
them very cheaply.
Something like this:

class complex:private Portland
{
// ...
public:
complex & operator = (const Portland &right)
{
Portland &left = *this;
left = right;
return *this;
}

operator Portland ()
{
Portland &left = *this;
return left;
}
};

or something similiar did not compile this could possibly not compile,
if you have a complex<T> template, specialize it for double like this.
some work but should allow easy interaction to Portland's functions.
if they use Porland *'s then add an operator Portland *() as well.

I don't see how a templated class can be used with a "C" API anyway....

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.