why Visual Studio can not optimize the initialization code?

G

George2

Hello everyone,


Why Visual Studio compiler can not optimize in this case? I think this
case is almost the same as sample 1, why compiler can optimize sample
1 but can not optimze sample 2?

(sample 2, http://msdn2.microsoft.com/en-us/library/ms364057(vs.80).aspx)

Code:
#include <stdio.h>
class A {
  public:
    A() {printf ("A: I am in constructor\n");i = 1;}
    ~A() { printf ("A: I am in destructor\n"); i = 0;}
    A(const A& a) {printf ("A: I am in copy constructor\n"); i = a.i;}
    int i, x, w;
};
 class B {
  public:
    A a;
    B()  { printf ("B: I am in constructor\n");}
    ~B() { printf ("B: I am in destructor\n");}
    B(const B& b) { printf ("B: I am in copy constructor\n");}
};
A MyMethod()
{
    B* b = new B();
    A a = b->a;
    delete b;
    return (a);
}
int main()
{
    A a;
    a = MyMethod();
}


thanks in advance,
George
 
R

Rolf Magnus

George2 said:
Hello everyone,


Why Visual Studio compiler can not optimize in this case?

Optimization is beyond the C++ language definition. Further, specific tools
are not discussed here. You should ask in a newsgroup about Visual Studio.
I think this case is almost the same as sample 1, why compiler can
optimize sample 1 but can not optimze sample 2?

(sample 2, http://msdn2.microsoft.com/en-us/library/ms364057(vs.80).aspx)

This web page is severely broken. It doesn't work in my browser, and the W3
validator reports 63 errors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top