|
Firstly does the code compile?
If not, it does not work,
if yes, It might work, ( i have not tested it)
the object will be created, method will be called and distroyed immediatly,
So you cant maintain any state for that object. So initialising the members of the class for future makes no sence.
so it is as good as calling a function called MyMethod which does some processing.
-prakash
-- modified at 23:15 Tuesday 11th October, 2005
|
|
|
|
|
Hello,
Your code is right. The C++ standard allows the modification of temporary objects.
What you do is create a temporary object on the stack (MyClass() creates the temporary). Second you call the MyMethor() function on the temporary. After the statement, the temporary is destroyed and you achieved nothing. In short, your object will be gone after the statement and will be useless. Maybe the compiler even removes the statement..
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
I see the light ... thanks for the explanation.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
You're welcome
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Well, actually I wrote this code and it works. The only thing I want is to get a return value of function MyMethod() and if I use for example:
int i = 5;<br />
int MyValue = MyClass().MyMethod(i);
the MyValue variable actually has got the value returned by function MyMethod(). So, I don't actually care in this case if that temporary object is destroyed as long as I can get the return value of it's function MyMethod().
By the way, I use Visual Studio .NET 2003 and I've noticed something strange about this:
class MyClass<br />
{<br />
public:<br />
MyClass();
MyClass(CString MyString);
int MyMethod(int MyVariable);<br />
};
I use this temporary object by calling a constructor with parameter, like:
CString MyString;<br />
MyString = "Example string";<br />
<br />
MyClass(MyString). <- at this moment I do nothing, and the list of variables and methods appears
But if I use a default constructor (with no parameters), like:
MyClass(). <- there's no list, although it should appear
I've noticed that the list of variables and methods appears when the code is ok, but if I have mistakes in the code, it doesn't appear. So if the list doesn't appear after calling a constructor without parameter, and if it appears after calling a constructor WITH parameter - something is not quite ok...
Thanks for replies.
|
|
|
|
|
Hi !
I need to replace some fields in the http header in all (http) traffic passing through my PC. I decided to do it via LSP.
The header I want to edit is in the WSPSend function of my LSP.
Here is the func declaration :
int WSPAPI WSPSend (
SOCKET s,
LPWSABUF lpBuffers, DWORD dwBufferCount, LPDWORD lpNumberOfBytesSent,
DWORD dwFlags, LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine, LPWSATHREADID lpThreadId, LPINT lpErrno )
The data I want to edit is in lpBuffers. The trick is that I don't know how many buffers (dwBufferCount) there can be and who is setting this value. In most cases it's set to 1. It means that we write lpBuffers[0].buf to get to the needed buffer.
When I try JUST to replace let's say the address in HOST field of the http header to the address with the same quantity of letters, then it's OK. Now, let I want to replace the address from 'www.yahoo.com' to 'www.microsoft.com', what should I do ? First I thought I have to free the old buffer (lpBuffers[0].buf) and set to new one, but when I do so, my IE crashes. So maybe I have to alloc new buffer and set its address to lpBuffers[1].buf and its length to lpBuffers[1].len ? Then who will free it ? Do I have to do that or the system ? If this is fault way to solve my task, then how can I do it all ?
-- modified at 18:37 Tuesday 11th October, 2005
|
|
|
|
|
Hello,
I want to paint text to a window usint CDC::PaintText or CDC::TextOut. The problem is, when I do this, the text is being painted in some ugly bold font. I just want to use the default Windows font.
So, how do I specify what font I want to use when using the CDC methods?
Or, how do I prevent the selection of the bad font I'm getting?
Thanks!
-Ian
|
|
|
|
|
|
|
You need to create the font, select it into the CDC, do the textout, then select it out.
You should always return any CDC object to the system in the same state as when you got it.
As for getting the default system font, you need to do a call to GetSystemParameterInfo or some such (I am at home and dont have the docs in front of me)
CFont font;
font.CreateFont(...);
CFOnt oldFont = (CFont*)dc.SelectObject(&font);
dc.TextOut(...);
dc.SelectObject(oldFont);
If you vote me down, my score will only get lower
|
|
|
|
|
Hi,
I get lastError code = 12003 when trying GetFile() as follows-
Could you tell me what is the error for this code and how to fix it.
Thanks !!
--my code (vc__6.0):
CInternetSession sess( _T("mysite"), 1, PRE_CONFIG_INTERNET_ACCESS);
CFtpConnection* pConnect = NULL ;
sess.GetFtpConnection( _T("ftp.mysite.com") , _T("me") , _T("pwd") ) ;}
if( ! pConnect->GetFile( _T("bcu.txt") , _T("c:\\tou.txt") , FALSE ) )
{
DWORD dw = GetLastError();
}
|
|
|
|
|
|
How can one separate multiple groups of radio buttons? I already made a group of them working, but what if I want a totally separate one? How and where can I put it? I got a group of 4 radio buttons in a side, and another group of 4 in another side. In the first group, that "group" checkbox is checked on one of the radio buttons, but the 4 radios in the other side are behaving like they're a part of the first group. Know what I'm sayin'?
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
The first radio button in the group, or the first control right after the group, must have the WS_GROUP style. All controls defined without the WS_GROUP style after the first control belong to the same group. The next control with the WS_GROUP style starts the next group.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
It's'a'working.
-= E C H Y S T T A S =-
The Greater Mind Balance
|
|
|
|
|
I need urgent to know if there is a function in Visual C++ 6
to obtain the size in bytes of a file
I saw that there is a function Filelen() but its for VisualBasic,
there is one similar in Visual C++
I need to know the size in bytes of one file .Wav to send it thorough a socket , but I dont know how to get the size
I have been tried with the function Fread to read the file and to know the size , but all the time it returns me 0,
can somebody help me Urgent !!!
REU
|
|
|
|
|
|
how can I get the Handle
to the file
is the first param in the GetFileSize function
can you help me
|
|
|
|
|
Ok I did it
thanx for your help brotha
the function GetFileSize its perfect (y)
thanx
GOD BLESS YOU
SHALOM
REU
|
|
|
|
|
situation : I'm converting a C struct into a C++ class.
now, I have a function AllocateC that will allocate ( malloc ) the C struct and do some initialization operations on that newly allocated struct.
MyStruct* AllocateStruct( )
{
MyStruct* p = malloc( ... );
DoSomething( p );
DoSomethingElse( p );
return p;
}
now, if I move this into a C++ class with a constructor:
MyStruct::MyStruct()
{
}
The problem is with the additional initialization ( DoSomething DoSomethingElse ) I think I cannot put those into the constructor because the
object is not yet finalized ( fully constructed ).
Is there a 2 step constructor "construct" that I can use, or do I have to keep using a wrapper function to do the new and the additional init.
Thanks.
Max.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Maximilien wrote:
The problem is with the additional initialization ( DoSomething DoSomethingElse ) I think I cannot put those into the constructor because the
for non-inherited class objects when the constructor is executing, the object is completely initialised, so it is safe to do the init there, but memory allocation in the constructor is really not a great way to go, what if there is an exception during memory allocation, not a pretty way to recover.
-prakash
|
|
|
|
|
A new Java-like framework has just been released by SwingC.com.
SwingC is a great UI framework that can be used in place of MFC, or any other GUI framework. It has a java-like syntax, and works flawlessly.
|
|
|
|
|
java! not my cup of coffee.
-prakash
|
|
|
|
|
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|