#include <iostream>
#include <cstdlib>
#include <cmath>
#include "SmrtPtr.hp p"
using namespace std;
struct Data
{
double plus;
double mult;
double pow;
};
SmrtPtr<Datamat h(const double& val,const double& val2);
int main()
{
for(;;)
{
cout << "Enter two values: " << endl;
double val, val2;
cin >val >val2;
SmrtPtr<Datatup le=math(val,val 2);
cout << tuple->plus << endl << tuple->mult << endl << tuple->pow <<
endl;
}
system("PAUSE") ;
return EXIT_SUCCESS;
}
SmrtPtr<Datamat h(const double& val,const double& val2)
{
SmrtPtr<Datatup le(new Data);
tuple->plus=val+val 2;
tuple->mult=val*val 2;
tuple->pow=pow(val,va l2);
return tuple;
// should the d-tor get called here?!?
}
Here's the code for the class' d-tor:
~SmrtPtr<T>()
{
DataBase->sub();
if(DataBase->status()==0)
{delete ptr; delete DataBase; cout << "Deleted." << endl;}
else {delete DataBase; cout << "Out of scope. " << endl;}
}
} 8 1326
"Protoman" <Pr**********@g mail.comwrote in message news:11******** *************@i 42g2000cwa.goog legroups.com...
#include <iostream>
#include <cstdlib>
#include <cmath>
#include "SmrtPtr.hp p"
using namespace std;
struct Data
{
double plus;
double mult;
double pow;
};
SmrtPtr<Datamat h(const double& val,const double& val2);
int main()
{
for(;;)
{
cout << "Enter two values: " << endl;
double val, val2;
cin >val >val2;
SmrtPtr<Datatup le=math(val,val 2);
cout << tuple->plus << endl << tuple->mult << endl << tuple->pow <<
endl;
}
system("PAUSE") ;
return EXIT_SUCCESS;
}
SmrtPtr<Datamat h(const double& val,const double& val2)
{
SmrtPtr<Datatup le(new Data);
tuple->plus=val+val 2;
tuple->mult=val*val 2;
tuple->pow=pow(val,va l2);
return tuple;
// should the d-tor get called here?!?
}
As I read that, it's returning a copy of a SmrtPtr object,
so a temporary is made. Since "tuple" is automatic storage
class, the original "tuple" should be destructed when math()
returns. The temporary copy is then returned to the calling
function.
Are you saying this is NOT what's happening when you run it?
Here's the code for the class' d-tor:
~SmrtPtr<T>()
{
DataBase->sub();
if(DataBase->status()==0)
{delete ptr; delete DataBase; cout << "Deleted." << endl;}
else {delete DataBase; cout << "Out of scope. " << endl;}
}
}
What does it print when you run it?
--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter) http://home.pacbell.net/earnur/
Robbie Hatley wrote:
"Protoman" <Pr**********@g mail.comwrote in message news:11******** *************@i 42g2000cwa.goog legroups.com...
#include <iostream>
#include <cstdlib>
#include <cmath>
#include "SmrtPtr.hp p"
using namespace std;
struct Data
{
double plus;
double mult;
double pow;
};
SmrtPtr<Datamat h(const double& val,const double& val2);
int main()
{
for(;;)
{
cout << "Enter two values: " << endl;
double val, val2;
cin >val >val2;
SmrtPtr<Datatup le=math(val,val 2);
cout << tuple->plus << endl << tuple->mult << endl << tuple->pow <<
endl;
}
system("PAUSE") ;
return EXIT_SUCCESS;
}
SmrtPtr<Datamat h(const double& val,const double& val2)
{
SmrtPtr<Datatup le(new Data);
tuple->plus=val+val 2;
tuple->mult=val*val 2;
tuple->pow=pow(val,va l2);
return tuple;
// should the d-tor get called here?!?
}
As I read that, it's returning a copy of a SmrtPtr object,
so a temporary is made. Since "tuple" is automatic storage
class, the original "tuple" should be destructed when math()
returns. The temporary copy is then returned to the calling
function.
Are you saying this is NOT what's happening when you run it?
Here's the code for the class' d-tor:
~SmrtPtr<T>()
{
DataBase->sub();
if(DataBase->status()==0)
{delete ptr; delete DataBase; cout << "Deleted." << endl;}
else {delete DataBase; cout << "Out of scope. " << endl;}
}
}
What does it print when you run it?
--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter) http://home.pacbell.net/earnur/
OK, here's the output:
Enter two values:
2 2
4
4
4
Deleted.
Press any key to continue...
Somewhere, it should be printing "Out of scope."
"Protoman" wrote:
#include <iostream>
#include <cstdlib>
#include <cmath>
#include "SmrtPtr.hp p"
using namespace std;
>
struct Data
{
double plus;
double mult;
double pow;
};
>
SmrtPtr<Datamat h(const double& val,const double& val2);
int main()
{
for(;;)
{
cout << "Enter two values: " << endl;
double val, val2;
cin >val >val2;
SmrtPtr<Datatup le=math(val,val 2);
cout << tuple->plus << endl << tuple->mult << endl << tuple->pow <<
endl;
}
system("PAUSE") ;
return EXIT_SUCCESS;
}
>
SmrtPtr<Datamat h(const double& val,const double& val2)
{
SmrtPtr<Datatup le(new Data);
tuple->plus=val+val 2;
tuple->mult=val*val 2;
tuple->pow=pow(val,va l2);
return tuple;
// should the d-tor get called here?!?
}
~SmrtPtr<T>()
{
DataBase->sub();
if(DataBase->status()==0)
{delete ptr; delete DataBase; cout << "Deleted." << endl;}
else {delete DataBase; cout << "Out of scope. " << endl;}
}
}
What does it print when you run it?
OK, here's the output:
Enter two values:
2 2
4
4
4
Deleted.
Press any key to continue...
Somewhere, it should be printing "Out of scope."
The fact that the d'tor printed ANYTHING shows that the d'tor
destructed one SmrtPtr object. Which one, I don't know for
sure, but I'm guessing it was tuple in math(). If you're
expecting it to tell you when it gets through destructing
all the SmrtPtr objects, then OK, but you're going to have
to get rid of that "system("PAUSE" );", because the final
d'tor calls will occur only AFTER you return from main.
So if you're launching this from an icon, you'll never see
that message, because it will only flash on your screen for
a nanosecond!
So get rid of the "system("PAUSE" );", launch a DOS window,
and launch the program from within the DOS window by typing
it's name. THEN you will see the final d'tor calls.
--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter) http://home.pacbell.net/earnur/
Robbie Hatley wrote:
"Protoman" wrote:
#include <iostream>
#include <cstdlib>
#include <cmath>
#include "SmrtPtr.hp p"
using namespace std;
struct Data
{
double plus;
double mult;
double pow;
};
SmrtPtr<Datamat h(const double& val,const double& val2);
int main()
{
for(;;)
{
cout << "Enter two values: " << endl;
double val, val2;
cin >val >val2;
SmrtPtr<Datatup le=math(val,val 2);
cout << tuple->plus << endl << tuple->mult << endl << tuple->pow <<
endl;
}
system("PAUSE") ;
return EXIT_SUCCESS;
}
SmrtPtr<Datamat h(const double& val,const double& val2)
{
SmrtPtr<Datatup le(new Data);
tuple->plus=val+val 2;
tuple->mult=val*val 2;
tuple->pow=pow(val,va l2);
return tuple;
// should the d-tor get called here?!?
}
>
~SmrtPtr<T>()
{
DataBase->sub();
if(DataBase->status()==0)
{delete ptr; delete DataBase; cout << "Deleted." << endl;}
else {delete DataBase; cout << "Out of scope. " << endl;}
}
}
>
What does it print when you run it?
OK, here's the output:
Enter two values:
2 2
4
4
4
Deleted.
Press any key to continue...
Somewhere, it should be printing "Out of scope."
The fact that the d'tor printed ANYTHING shows that the d'tor
destructed one SmrtPtr object. Which one, I don't know for
sure, but I'm guessing it was tuple in math(). If you're
expecting it to tell you when it gets through destructing
all the SmrtPtr objects, then OK, but you're going to have
to get rid of that "system("PAUSE" );", because the final
d'tor calls will occur only AFTER you return from main.
So if you're launching this from an icon, you'll never see
that message, because it will only flash on your screen for
a nanosecond!
So get rid of the "system("PAUSE" );", launch a DOS window,
and launch the program from within the DOS window by typing
it's name. THEN you will see the final d'tor calls.
--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter)
http://home.pacbell.ne t/earnur/'
I'll try that.
"Protoman" <Pr**********@g mail.comskrev i meddelandet
news:11******** *************@i 42g2000cwa.goog legroups.com...
snip
SmrtPtr<Datatup le=math(val,val 2);
snip
>
SmrtPtr<Datamat h(const double& val,const double& val2)
{
SmrtPtr<Datatup le(new Data);
tuple->plus=val+val 2;
tuple->mult=val*val 2;
tuple->pow=pow(val,va l2);
return tuple;
// should the d-tor get called here?!?
}
The short answer is: It might, but it doesn't have to.
This is an example of the Named Return Value Optimization (NRVO)
specifically allowed by the language standard. The math function
creates a local variable, that is only used to initialize an outer
variable. In that case, the compiler is allowed to skip the local
variable and construct the result directly into the outer variable.
Bo Persson
Bo Persson wrote:
"Protoman" <Pr**********@g mail.comskrev i meddelandet
news:11******** *************@i 42g2000cwa.goog legroups.com...
snip
SmrtPtr<Datatup le=math(val,val 2);
snip
SmrtPtr<Datamat h(const double& val,const double& val2)
{
SmrtPtr<Datatup le(new Data);
tuple->plus=val+val 2;
tuple->mult=val*val 2;
tuple->pow=pow(val,va l2);
return tuple;
// should the d-tor get called here?!?
}
The short answer is: It might, but it doesn't have to.
This is an example of the Named Return Value Optimization (NRVO)
specifically allowed by the language standard. The math function
creates a local variable, that is only used to initialize an outer
variable. In that case, the compiler is allowed to skip the local
variable and construct the result directly into the outer variable.
Bo Persson
I think Dev-Cpp is doing that, then. But wait, how can it skip the
construction of tuple; it's members are being assigned to. If it skips
th construction of tuple, what is being assigned to then?
"Protoman" <Pr**********@g mail.comskrev i meddelandet
news:11******** ************@35 g2000cwc.google groups.com...
>
Bo Persson wrote:
>"Protoman" <Pr**********@g mail.comskrev i meddelandet news:11******* **************@ i42g2000cwa.goo glegroups.com.. .
snip
SmrtPtr<Datatup le=math(val,val 2);
snip
>
SmrtPtr<Datamat h(const double& val,const double& val2)
{
SmrtPtr<Datatup le(new Data);
tuple->plus=val+val 2;
tuple->mult=val*val 2;
tuple->pow=pow(val,va l2);
return tuple;
// should the d-tor get called here?!?
}
The short answer is: It might, but it doesn't have to.
This is an example of the Named Return Value Optimization (NRVO) specifically allowed by the language standard. The math function creates a local variable, that is only used to initialize an outer variable. In that case, the compiler is allowed to skip the local variable and construct the result directly into the outer variable.
Bo Persson
I think Dev-Cpp is doing that, then. But wait, how can it skip the
construction of tuple; it's members are being assigned to. If it
skips
th construction of tuple, what is being assigned to then?
It is being assigned to the outer tuple variable (in main), where the
result will end up anyway. You can think of it as-if it was written
(almost) like this:
void math(const double& val,const double& val2, SmrtPtr<Data>& tuple)
{
tuple = new Data;
tuple->plus=val+val 2;
tuple->mult=val*val 2;
tuple->pow=pow(val,va l2);
return;
// no d-tor gets called here!
}
Bo Persson
Protoman wrote:
[snip]
Bo Persson wrote:
>> The short answer is: It might, but it doesn't have to.
This is an example of the Named Return Value Optimization (NRVO) specifically allowed by the language standard. The math function creates a local variable, that is only used to initialize an outer variable. In that case, the compiler is allowed to skip the local variable and construct the result directly into the outer variable.
I think Dev-Cpp is doing that, then. But wait, how can it skip the
construction of tuple; it's members are being assigned to. If it skips
th construction of tuple, what is being assigned to then?
Of course it will still have to construct the object. What Bo Persson
meant was that, instead of creating a local object and returning a copy
of it to the caller, an implementation is allowed to provide an
optimization where a single copy of the object is created, where the
outgoing variable would be. This way, the object manipulated within the
function and that which will be returned to the calling code are the
same, not copies.
Regards,
--
Ney André de Mello Zunino This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: tuvok |
last post by:
Is it correct that the virtual dtor of base gets called implicitly?
Here's some code to demonstrate what I mean:
Class B has a virtual destructor, so has class D which
is derived from B. Deleting D calls the dtor of D and
then the dtor of B.
I was thinking that this would be true only for non-virtual dtor case,
but I wouldn't have expected it happen for a virtual dtor.
For a class with a virtual dtor I would have expected that only
the...
|
by: Martin |
last post by:
Hi,
Since I went ASP.NET with my global.asa (making it a global.asax) the
application events are called just fine as well as the Session_OnStart event
but the Session_OnEnd event is not. What is wrong? My global.asax looks like
this:
<%@ Application src="app.cs" Inherits="mwte.App" %>
|
by: Sally |
last post by:
Just confused about when OnInit and Constructor gets called in the
parent/child case.
Page.Constructor()
Page.AddParsedSubObject() <- do all the sub's constructors get called
here?
Page.OnInit() Children.OnInit() (from what I have read, no particular
oder)
|
by: Vishal |
last post by:
Hello,
I have overrided the LoadViewState function in my
webform. However when the page postsback the function is
never called. Here is how I overrided it.
Protected Overloads Sub LoadViewState(ByVal SavedState As
Object)
Response.Write("LWS: " & ViewState("Stores"))
CreateColumns()
|
by: Niels Dekker (no reply address) |
last post by:
When calling swap as follows (as recommanded in Effective C++, 3rd
Edition, by Scott Meyers), what swap is chosen to be called?
using std::swap;
swap(a, b);
Suppose there is a global ::swap function provided, whose parameter type
matches closer to the type of a and b than any of the std::swap
overloads does. Will this ::swap be called, or is std::swap still
preferred? I ask this because the compilers I tried disagree! So will
any of...
| |
by: sean |
last post by:
I'm trying to create "rubber-band" rectangles by overriding the
OnPaint method to place rectangles on top of all graphic controls, but
when I call Me.Invalidate() (when the user moves the mouse), OnPaint
is not getting called... Here is the relevent code:
I'm trying to create a "rubber band" rectangle effect on my form.
Private Sub HighlightSectionOfTrack(ByVal sender As Object, ByVal e
As
System.Windows.Forms.MouseEventArgs) Handles...
|
by: R.A.M. |
last post by:
Hello,
I am writing ASP.NET application. I would like to use forms authenication. I
created Login.aspx page and modified Web.config. Start page is Default.aspx.
The problem is that Login.aspx is not called.
Here is part of my Web.config.
<authentication mode="Forms">
|
by: notbob |
last post by:
I'm trying to learn how to program. I'm using:
How to Think Like a Computer Scientist
Learning with Python
2nd Edition
Am I likely to receive any help, here, or is there another irc, forum, etc,
that might better serve a complete amateur such as myself. Thnx.
|
by: suresh |
last post by:
Hi
Could you please tell why copy constructor is not called in the first
line in main(), as mentioned in the text books. I used g++ version
4.1.2 on debian etch
thanks
suresh
# include <iostream>
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |