|
Thank you. I understand what is going on. I don't want to keep asking stupid questions.. but if that is the case, then how would you solve this problem.
suppose you have a class, and this class has some pointers to different objects.. now some functions of the class need to be able to modify the data of what the pointer points too, but you also have some functions that just need to retrieve the data, and you want to make sure that those functions do not modify the pointed to data.
|
|
|
|
|
How about
int * const pTemp = m_pInt;
so in the function you always access a const pointer ? I can't think of an iron clad solution, i.e. one that does not rely on the functions implimenter 'playing by the rules'. Unless I have external clients, I don't use const functions much at all, and if you declare it const and don't modify anything, then the fact that you could is immaterial, you made a contract with your classes clients and you kept it.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
It'd probably be fairly easy to make a bot that'd post random stupid VB questions, and nobody would probably ever notice - benjymous - 21-Jan-2003
|
|
|
|
|
Thank you Christian. That was the answer I came up with, but with my limited experince, I just wanted to make sure.
|
|
|
|
|
const prevents the method from changing the value of any data members. In this case, it's the pointers. You're changing the value of what is being pointed to.
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed)
NEW: Awasu v0.7[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Taka Muraoka wrote:
const prevents the method from changing the value of any data members
Not quite. const is a contract, a promise, to not change the logical state of an object, when applied to a member function.
Imagine a class that has a backing store (e.g. a database) for the data it can present to the user. Any GetFoo() should probably be a const member function.
Later on you realize "Hey, this stuff is waaay to slow. I need a cache!". You implement such a cache. But, that would change the objects state, right? No. This is where the mutable keyword come in play.
A const member function may modify mutable qualified data - even that the "contract" you have with the clients of that code promises that it may not change the objects logical/observable state.
This is just scraping the top of the iceberg. Const correctness is an artform in itself, and depending on scope it can mean a whole lot of things.
For further information, I think Marshall Cline's C++ FAQ Lite could be a good starting point.
|
|
|
|
|
i would to retreive a handel of window of ACROBAT for PDF document ,and i don't know how to use FindWindow("?","?").can you help me
|
|
|
|
|
aguest wrote:
and i don't know how to use FindWindow("?","?").can you help me
Read this[^].
Nick Parker
The only man who never makes a mistake is the man who never does anything. - Theodore Roosevelt
|
|
|
|
|
Hi all,
I am new to encrypt and decrypt.
I want to encrypt/decrypt a fixed length small block of data. It is there any sample methord that don't need key?
Thanks
laura
|
|
|
|
|
add 128 to each byte. that's about as secure as you can get, without using a key of some kind.
-c
A | B - it's not a choice.
|
|
|
|
|
Chris Losinger wrote:
add 128 to each byte. that's about as secure as you can get, without using a key of some kind
But wouldn't 128 be a sort of a key too?
--
karl
|
|
|
|
|
Would someone help me by telling me why this doesnt work? I'm trying to write an easy way for me and my co-admins to change users passwords w/o using the standard tools. Note, that the DC= parts reflect my current Active Directory DC on my test machine. I know for a fact that the user I am requesting is at CN=UserName,CN=Users,DC=HOME,DC=Local.
void CChangePWDDlg::OnChangepw()
{
CString sUID, sPassword, sPWConfirm;
GetDlgItemText(IDC_USERID, sUID);
GetDlgItemText(IDC_PASSWORD, sPassword);
GetDlgItemText(IDC_PWCONFIRM, sPWConfirm);
if (sUID.GetLength() == 0)
{
AfxMessageBox("User ID cannot be empty");
return;
}
if (sPassword.GetLength() == 0)
{
AfxMessageBox("Password cannot be empty");
return;
}
if (sPWConfirm.GetLength() == 0)
{
AfxMessageBox("Re-Enter Password");
return;
}
if (strcmp(sPassword, sPWConfirm) != 0)
AfxMessageBox("Passwords Don't Match");
else
{
CString objPath = "LDAP://CN=";
objPath = objPath += sUID;
objPath = objPath += ",CN=Users,DC=HOME,DC=Local";
BSTR oPath = objPath.AllocSysString();
IADsUser *pUser;
HRESULT h2;
h2 = ADsGetObject(oPath, IID_IADsUser, (void**) &pUser);
if (FAILED(h2))
{
AfxMessageBox("Failed to get user");
SysFreeString(oPath);
pUser->Release();
return;
}
else
{
SysFreeString(oPath);
BSTR oPass = sPassword.AllocSysString();
HRESULT hr;
hr = pUser->SetPassword(oPass);
pUser->Release();
if (FAILED(hr))
{
AfxMessageBox("Failed to set password");
return;
}
else
{
SetDlgItemText(IDC_USERID, "");
SetDlgItemText(IDC_PASSWORD, "");
SetDlgItemText(IDC_PWCONFIRM, "");
}
}
}
}
I always receive "Failed to get user".
Thanks,
Frank
PS. Alot of this code was used from examples on MSDN.
|
|
|
|
|
Hello guru's around the world!
I'm writing some software to handle some simple home-made hardware under windows2000.
I need to use 2 input and 2 output channels, being: DSR, CTS, RTS, DTR. I open the serial port using CreateFile(..) , non overlapped. Toggleing the output channels with EscapeCommFunction(..) works fine too.
A worker tread is in an infinite loop (while(true)) in which it waits for a WaitCommEvent(..) . When the DSR or the CTS lines change state, I get notified - just as it should be.
But I want to keep polling with WaitCommEvent(..) and I want to use EscapeCommFunction(..) to toggle the output lines.
To be more exact, I need to be able to give pulses to the DTR and watch what happens to the CTS (input). Unfortunatly, EscapeCommFunction(..) hangs if WaitCommEvent(..) is still waiting for an event.
Do I NEED to use overlapped IO for this? Or is it possible to change the DTR status while polling the CTS?
Thanks in advance,
Regards,
Griffith Sutherns
Everything you say will be misquoted, ripped out of context and used against you.
|
|
|
|
|
In non-overlapped IO each call will block the IO resource.
You will also run into problems when you try to exit from your thread because it will be stuck on WaitCommEvent.
You have a couple of choices:
1. Don't use WaitCommEvent and instead poll the IO with GetCommModemStatus.
Polling can be OK if done infrequently.
2. Use overlapped IO. A little more complicated but it won't block the IO resource.
I'd go with overlapped IO.
Col
|
|
|
|
|
Thanks a lot Colin!
I'll look into GetCommModemStatus first, that might just be what I was looking for. Although I do need need to poll about 80 times in a few seconds, it might still work reliably.
Once again, your help's greatly appriciated.
Regards,
Griffith
Everything you say will be misquoted, ripped out of context and used against you.
|
|
|
|
|
BTW,
Since you plan to poll you should do it at least double the maximum possible expected input frequency to ensure you do not miss a pulse.
Col
|
|
|
|
|
I use visual studio.net enterprise architect
I'm coding an app with MFC.
I have a problem. After including some source directory (containing *.inl) into the include path of the project properties, VS.net crash when I use project -> 'add ressource'.
Any Ideas?
Everything's beautiful if you look at it long enough...
|
|
|
|
|
why this routine stops everytime with the errorMessageBox??
thx for help.
m_Path: absolute path to the file (for example "c:\data\test.log"
void CTestDlg::OnOK()
{
this->UpdateData(true);
CString error;
CStdioFile logFile;
CFileException fileException;
if (!logFile.Open( m_Path, CFile::modeRead ),
&fileException )
{ //ERROR
error.Format( "Can't open file %s, error = %u\n",
m_Path, fileException.m_cause );
MessageBox(error,NULL,MB_OK);
}
else
{ //all okay
logFile.Close();
}
CDialog::OnOK();
}
|
|
|
|
|
what does fileException.m_cause contain?
-c
A | B - it's not a choice.
|
|
|
|
|
the errorcode...
but i think i found the problem...
its strange... 1 day searching without success
and some minutes after this post i found a wrong placed ")"
in the if-cause ...
the ")" should be after the exception-var...
|
|
|
|
|
Hello,
I have some really simple wininet code that performs and http post and closes the handles when done. I am having a problem where on app exit, I perform a final http post and close all of my handles without fail and exit my wininet function, but the app refuses to unload until after a 60 second pause. Any ideas why?
|
|
|
|
|
Is there a simple way inside the VS6 IDE to automatically change the color of code between a #if ... #endif, preferable when using #if 0 ... #endif, which effectively removes an entire section of code? Since comments between /* ... */ can be colored, can't this be done with #if too?
Thanks,
Dave
"You can say that again." -- Dept. of Redundancy Dept.
|
|
|
|
|
For this situation, you must use macro. Writing a macro to do what you want!
A. Riazi
|
|
|
|
|
Nope, there's no way to do it.
I personally avoid leaving portions of commented-out code in my source files, whether it's with /*...*/ or #if 0. If something needs to be removed, I delete it, and I rely on my version control software to let me recover it later if necessary. I just hate looking at code with old junk all over it.
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
You might want to look at Visual Assist, from Whole Tomato Software
www.wholetomato.com[^]
--
Where are we going? And why am I in this handbasket?
|
|
|
|
|
I am about to write code that will perform a dynamic_cast from Base* to Derived* in a function that got the Base* from a 'this' in a constructor.
Example :
<br />
class Base;<br />
void do_stuff( Base* );<br />
<br />
class Base<br />
{<br />
public:<br />
Base( );<br />
};<br />
<br />
class Derived : public Base<br />
{<br />
public:<br />
Derived( )<br />
{<br />
do_stuff( this );<br />
}<br />
};<br />
<br />
void do_stuff( Base* pBase )<br />
{<br />
Derived* pDerived = dynamic_cast< Derived* >( pBase );<br />
if( pDerived )<br />
do_more_stuff( pDerived );<br />
}<br />
I know using an object's virtual functions within its constructor is bad, because the virtual function table is not completely built yet. I have read about dynamic_cast stating that it can convert complete objects to complete objects, is that related to the vtable?
So, can I dynamic_cast<> a 'this' in a constructor?
----------------
Blaster
Computer game programmer and part time human being
http://www.blastersoft.com
|
|
|
|