Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7936221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:08:53+00:00 2026-06-03T22:08:53+00:00

It seems that I’m doing here something terribly wrong. Can you help me? The

  • 0

It seems that I’m doing here something terribly wrong. Can you help me? The aim is to use inner_product for complex vectors.

#include<iostream>
#include<vector>
#include <numeric>
#include <complex>


using namespace std; 



template<class T>
complex< T > complex_prod(complex< T > a, complex< T > b)
{
 return conj<T>(a)*b; 
}

template<class T>
complex< T > add_c(complex< T > a, complex< T > b)
{
  return a+b;
}

int main()
{
  complex<double> c1(1.,3.);
  complex<double> c2(2.,4.);

  vector<complex<double> > C1(3,c1);
  vector<complex<double> > C2(3,c2);

 cout<<inner_product(C1.begin(),C2.end(),C2.begin(),0.,add_c<double>,complex_prod<double>) <<endl;

return 0;
}

I don’t see why there is a conversion problem, everything seems to be defined and the iteration should make no problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:08:55+00:00Added an answer on June 3, 2026 at 10:08 pm

    The problem is that inner_product needs to know the type of the initial value, so you need to pass it an std::complex instead of a 0.:

    inner_product(C1.begin(),C2.end(),C2.begin(),std::complex<double>(0.,0.),add_c<double>,complex_prod<double>);
    

    or simply,

    inner_product(C1.begin(),C2.end(),C2.begin(),std::complex<double>(),add_c<double>,complex_prod<double>);
    

    Although an std::complex<double> can be implicitly constructed from a single numeric type

    std::complex<double> c = 2.*4.*300;
    

    the inner_product template looks like

    template<
        class InputIterator1,
        class InputIteratorr2,
        class T,
        class BinaryOperation1,
        class BinaryOperation2
    > T inner_product( InputIterator1 first1, InputIterator1 last1,
                       InputIterator2 first2, T value,
                       BinaryOperation1 op1,
                       BinaryOperation2 op2 );
    

    so there is a template parameter for the value. So there is no way the compiler can know you mean std::complex<double> here, it just interprets 0. as double.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that MSMQ doesn't use any Database management system to manage messages. How
It seems that when we use form_for @story do |f| then Story has to
Seems,that very basic question. Anyway can't get the meaning of next definition from Spring
Seems that web.xml for a servlet has an element called <enabled>false</enabled> that can be
Seems that my VS2008 help index has finally become FUBAR. It's already a known
Seems that when i create an object, the time is not correct. You can
It seems that I pressed something on the keyboard and these green arrows appeared
It seems that following code is wrong, as on the first call the code
Seems that question old as world, but I still can't find out the solution..
Seems that I can't store the linguettaCorrente variable into the hover handler : $('.navigatore_blocco').hover(

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.