|
Hi all,
I am wondering that the following is working. When will the temporary string, created in the constructor, destroyed? After constructor call or after object destroyed? Am I right that c_str() returns only the pointer and not copy char string? Is it a safe program or not?Thanx for your time,
#include <string>
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
class a
{
public:
const char * name;
a(const char * name_ ):name(name_){};
void print() {cout<
|
|
|
|
|
Ilia Oussorov wrote:
When will the temporary string, created in the constructor, destroyed? After constructor call or after object destroyed?
The 'name' variable belongs to the constructor, not the class itself. Therefore, it will lose validity when the constructor goes out of scope.
|
|
|
|
|
Why the program is working? Can you demonstrate this?
|
|
|
|
|
I see nothing that indicates that it won't work (this from just a cursory glance), although I'm not sure what it is trying to do.
|
|
|
|
|
Sorry, I have to explain it more exact.
a oa( ((string)"aaa"+(string)"bbb").c_str());
above line passes the pointer on temporary object ( of type const char*) to the constructor. After the end of constructor this object (character seq"aaabbb") should lose validity as you wrote.
But next line oa.print() prints correct object. Is it only a luck, that the memory was not overwritten or temporary object still exists?
If you mean this is a luck, I would very appreciate the suggestion how to demonstrate this
|
|
|
|
|
Ilia Oussorov wrote:
Is it only a luck, that the memory was not overwritten
Correct.
Ok, upon examining your code more closely, my last responses were less than accurate. Sorry about that. Some of your code was lost because of HTML formatting so I wasn't sure if the missing code was intentional or not.
The only way to guarantee that the print() method works is to allocate memory to the name member variable and copy the contents of the name_ parameter to it.
|
|
|
|
|
I use RTX(real time extension)to Pragram. after connected the shared memery, I save a value in the parameter of the shared memery. but when the program runs, the informationg"RTX NT Starvation Timeout(5000 MS). All RTSS processes stopped Debug and/or use "RTSSkill"command to unload all process images.(Poc=809799C8,Thread=807A8930)" comes allways. what's the reason?
|
|
|
|
|
Hi friends,
I want to place the cursor in a Text Box when the dialog box displayed asking for user name and password, default there is no cursor, How to do this??
Thanks in advance
Regards,
Satya
|
|
|
|
|
Or, call GotoDlgCtrl(GetDlgItem(IDC_MY_EDIT_CTRL)) in OnInitDialog and return FALSE.
onwards and upwards...
|
|
|
|
|
Hi WiB,
I couldn't get what U told, How to set the tab order, can u explain. What will happen if I change the return value.
Thank You,
Satya
|
|
|
|
|
hi i want to detect the presence of network (internet , lan ) , how do i approach.
need some some sortof driver event that is fired as soon as the net is there.
e.g as soon as u put LAN cable in card , your nework gets activated.
for e,g ICQ , as soon as u are connected , it logs in.
any detailed ideas.
regards
TIA
t
|
|
|
|
|
See if this helps:
http://www.pcausa.com/resources/InetActive.txt
|
|
|
|
|
Hello,
I have a text file with the following layout.
COMMAND1
ITEM1 Value1 Value2 Value3 Valu4
ITEM2 Value1 Value2 Value3 Valu4
ITEM3 Value1 Value2 Value3 Valu4
ITEM4 Value1 Value2 Value3 Valu4
...
ITEM_N
COMMAND2
ITEM1 Value1 Value2 Value3 Valu4
ITEM2 Value1 Value2 Value3 Valu4
ITEM3 Value1 Value2 Value3 Valu4
ITEM4 Value1 Value2 Value3 Valu4
...
ITEM_N
COMMAND3
ITEM1 Value1 Value2 Value3 Valu4
ITEM2 Value1 Value2 Value3 Valu4
ITEM3 Value1 Value2 Value3 Valu4
ITEM4 Value1 Value2 Value3 Valu4
...
ITEM_N
....
COMMAND_N
In this file, I have to insert new items, or change values of items or delete existing items.
For suppose if I want to insert new item under "COMMAND1", what I am doing is, seeking the pointer to the end of "COMMAND1", writing remainig text into a temporary file, inserting my new text, then appending the text which is stored in temporary file. But I guess, it is not a best method. It takes much time every time I insert/edit text.
Is there any other alternative to do this. Can anybody tell what is the best method to do this.
Thanks & regards,
Chito
|
|
|
|
|
Well the assumption is rather correct but there is too many calls to the file. you should read the content of the file to the memory. Then do all the opertions (parsing, reallocation etc) and then the buffer (with the new value) should be written to the file again.
The content fo your file looks like it can be easly stored by xml. And will be easier to parse.
Have a good day
|
|
|
|
|
One solution is file-mapping.
Kuphryn
|
|
|
|
|
i create a regular dll named MyDll using MFC, i want the dll popup a dialg in
the beginning of the function CMyDllApp::InitInstance() ,just as i did in my exe. but here caused serious error in wincore.cpp (line:884)
BOOL CMyDllApp::InitInstance()
{
// TODO: Add your specialized code here and/or call the base class
CDlg dlg;
dlg.DoModal();
return CWinApp::InitInstance();
}
who can tell me what's wrong to my program?
gucy
|
|
|
|
|
gucy wrote:
i create a regular dll named MyDll using MFC...
If by "regular dll" you mean a non-MFC DLL, this is rather contradictory, don't you think?
gucy wrote:
who can tell me what's wrong to my program?
I would guess that it's too early to be calling such functions. The DLL is not fully initialized at this point, and something within CDialog requires the DLL to be up and ready to go.
|
|
|
|
|
http://www.thesoftwareobjects.com
|
|
|
|
|
What does the software object to?
I'm guessing its demanding parity
'--8<------------------------
Ex Datis:
Duncan Jones
Merrion Computing Ltd
|
|
|
|
|
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
One would assume you are connected with this business. You should say so or not, and don't post anonymously.
There is only one C++ product on the site, so I can't see it being very usefull to folks here at CP. The site also seems difficult to use to me at least.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Hi,
I want to implement a function to lookup internet IP address to get its coresponding netblock information in my developing internet app.
Perhaps,my question is how to get WHOIS information in my program. Should my app connect to WHOIS server, such as APNIC WHOIS server?
For example,
if I lookup 202.84.144.73, I want to get its information
inetnum: 202.84.128.0 - 202.84.191.255
netname: HKT,HK
... and so on.
Any ideas? Thanks in advance.
|
|
|
|
|
|
Hi,
did you take a look at this article?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
i have developed a application. in which a child window opens on clicking a button
but if user moves parent window to corner of screen ; child window gets opened on the center of parent window not on screen
i wanted to display it in the center of screen irrespective of position of parent window.
thankong you
chan
|
|
|
|