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 3854536
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:38:16+00:00 2026-05-19T17:38:16+00:00

After putting some code to work, I’m trying to optimize it. One thing that

  • 0

After putting some code to work, I’m trying to optimize it. One thing that I’m trying to avoid is the creation of temporaries. Given a class

class foo{
   private:
     int a;
   public:
     foo(int sa):a(sa);
     ~foo(){}
    inline int multiply(int b) {return a*b;}//temporary?
};

The intel compiler is giving me the temporary created/reference temporary used here. Is any temporary variable being created?

EDIT: edited the return type. Also, I think that no temporary variable is being created in multiply, but the intel compiler gives me an error about that.

EDIT 2: After the requests below, here is a FULL code that the intel compiler v. 12 gives the error:

 #include <iostream>
 #include <complex>

 using namespace std;
 const double pi = 3.1415;
 const complex <double> I = (0.0,I);
 const complex <double> oneover2piI = (1.0 / (2.0 * pi * I));

  class foo{
     private:
       complex <double> a;
     public:
       foo(complex <double> sa):a(sa){}
       ~foo(){}
       inline complex <double> multiply(complex<double> b) 
       {return  a*sqrt(b);}
   };

The compilation line is

  icc -g -O2 -w2 -debug parallel -Wcheck -Weffc++ -mp -fp-stack-check -wd981 -wd2015 -wd1418  test.cpp -o  test

And the resulting warning is

  test.cpp(7): remark #383: value copied to temporary, reference to temporary used
  const complex <double> oneover2piI = (1.0 / (2.0 * pi * I));
                                         ^

The question was to understand what the compiler is balking at, and not to be hanous.

Thanks!

  • 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-05-19T17:38:17+00:00Added an answer on May 19, 2026 at 5:38 pm

    I think the compiler issues a warning because it translates:

    const complex <double> oneover2piI = (1.0 / (2.0 * pi * I));
    

    to invoke a default copy constructor:

    Object::complex<double>(const complex<double>&)
    

    which takes a reference of the temporary object as the argument, and makes a shallow copy (that results in data sharing if you use pointers) of the object. Basically this data sharing + temporary lifespan is the core of the problem. Take a look at the “academic” class below.

    #include<iostream>
    
    class A
    {
    
    public:
    
      A()
        :attribute(new char[10]) {}
    
      ~A()
      {
        std::cout << "d'ctor" << std::endl; 
        if(attribute){
          delete [] attribute;
          attribute = 0;
        }
      }
    
      A& operator +(const char& n)
      {
        //do some operation
        return *this;
      }
    
      void reset_attribute(char *new_ptr)
      {
        attribute = new_ptr;
      }
    
    private:
    
      char *attribute;
    };
    
    int main()
    {
      {//new scope to invoke destructors
        A b;
        A c = b;
        b.reset_attribute(new char[10]);
      }//no problem in this scope
    
      A a = (A()+2);//problem with a temporary object
    
      return 0;
    }
    

    the cygwin output:

    $ ./a.exe
    d'ctor //this is from b or c
    d'ctor //this is from b or c
    d'ctor //this is from temporary
    d'ctor //this is from a
    Aborted (core dumped)
    

    The delete operation has been executed twice on the same pointer, because it was shared between the temporary object and a.

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

Sidebar

Related Questions

Update: After some experimentation, it appears that the thing that is slow is when
After being told by at least 10 people on SO that version control was
After hours of debugging, it appears to me that in FireFox, the innerHTML of
After I was convinced that labeled breaks/continues are a total nono over here ,
I've written some Ruby code to inspect ZIP-files as part of an internal company
after trying to solve the problem without and with help I'm still stuck. My
After reading the Head First Design Patterns book and using a number of other
After the suggestion to use a library for my ajax needs I am going
After reading this question , I was reminded of when I was taught Java
After upgrading to the latest version of TortoiseSVN (1.5.2.13595), it's context menu is no

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.