|
Maximilien wrote: ...the string contains single backslash ( c:\max ) and letters will be "escaped" out of the string.
This is only the case with string literals.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
that's strange, because escaping a backslash matters only in the source code... if the user enters in the edit box a path (which is for him compound of sigle slashes of course), that will behave as if you had written in your source code the path with '\\' characters...
and same in the debugger. it does display single slashes, but look at the ascii code of the characters, and you'll see that no way you need (and you musn't !!!) replace single slashes with double ones...
but i can't help you much, because i have no compiler with me at the moment...
|
|
|
|
|
toxcct wrote: that's strange, because escaping a backslash matters only in the source code... if the user enters in the edit box a path (which is for him compound of sigle slashes of course), that will behave as if you had written in your source code the path with '\\' characters...
Definitely true .
toxcct wrote: but i can't help you much, because i have no compiler with me at the moment...
I had it and made the attempt [^], [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
|
Question about the 'this' pointer and properly returning a reference to an object.
I am learning about OOP and working through some examples. One of the examples has me overloading the *= operator.
<br />
CRegister& CRegister::operator *=(const CRegister &rhs)<br />
{<br />
this->m_dStore *= rhs.m_dStore;<br />
return *this;<br />
<br />
}<br />
I have two questions, why does an overloaded operator need to return a reference to the lvalue? Second if I did want to return the address of the lvalue shouldn't the code look like this?
<br />
CRegister& CRegister::operator *=(const CRegister &rhs)<br />
{<br />
this->m_dStore *= rhs.m_dStore;<br />
return &this;<br />
<br />
}
Or because 'this' is a pointer, by returning '&this' am I creating a second level of indirection, because i don't want the address of the 'this' pointer, but rather the address that the 'this' pointer points to?
Thanks guys,
Joe
|
|
|
|
|
TheDelChop wrote: why does an overloaded operator need to return a reference to the lvalue?
In fact an assignment operator (like *= ) must return a l-value .
TheDelChop wrote: Or because 'this' is a pointer, by returning '&this' am I creating a second level of indirection, because i don't want the address of the 'this' pointer, but rather the address that the 'this' pointer points to?
Your guess is right. this is a pointer to the object itself, *this is a reference to the object itself.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: TheDelChop wrote: why does an overloaded operator need to return a reference to the lvalue?
In fact an assignment operator (like *=) must return a l-value.
No, it doesn't. It can return anything or nothing. The only requirement is that it takes two arguments: if it's a global function (usually a friend function) two explicit arguments, at least one being a user defined type; if it's a member function the this pointer is the first implicit argument and the second must be explicitly supplied. In most common usages the return type is a reference to the class to which the operator belongs, but this is not a requirement.
Steve
|
|
|
|
|
Stephen Hewitt wrote: CPallini wrote:
TheDelChop wrote:
why does an overloaded operator need to return a reference to the lvalue?
In fact an assignment operator (like *=) must return a l-value.
No, it doesn't.
At least, it should (MSDN on assignment operator):
The operator returns the object to preserve the behavior of the assignment operator,which returns the value of the left side after the assignment is complete. This allows writing statements such as:
pt1 = pt2 = pt3;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: The operator returns the object to preserve the behavior of the assignment operator,which returns the value of the left side after the assignment is complete. This allows writing statements such as:
pt1 = pt2 = pt3;
As I said – this is normally the case (returning a reference) – but not a requirement as you suggested.
Steve
|
|
|
|
|
When you declare a variable the & does not mean "address of" but rather "reference". ie
int i = 1;
int &ri = i;
ri = 2;
int *pInt = &i;
int &r2 = *pInt;
r2 = 3;
Steve
|
|
|
|
|
TheDelChop wrote: why does an overloaded operator need to return a reference to the lvalue?
So you can write chained assignments like x = y = z; If y=z doesn't return a reference to y , then the second assignment may not compile, or may call some other operator= that you weren't expecting.
|
|
|
|
|
Michael Dunn wrote: So you can write chained assignments like x = y = z; If y=z doesn't return a reference to y, then the second assignment may not compile, or may call some other operator= that you weren't expecting.
Nice, this is exactly the explanation I was looking for. Thank you very much Mike.
|
|
|
|
|
Hi,
I have a key, for that i need to change the permissions for admins to full control, system to full control and power usres to only have read access and all others should not have access.
i have written this code,RegSetRegisterKey API is executing correctly, but if i open the registry using regedit, and open the dialog box for permissions, it is not checking the check boxes for full control and read access.
How to make these check boxes to check for the respective permissions.
SID_IDENTIFIER_AUTHORITY securityid = SECURITY_NT_AUTHORITY;
PSID pAdministratorsSid = NULL;
PSID pSystemSid = NULL;
PSID pPowerusersSid = NULL;
SECURITY_DESCRIPTOR sd;
PACL pDacl = NULL;
DWORD dwAclSize;
HKEY hKey;
LONG lRetCode;
BOOL bSuccess = FALSE;
lRetCode = RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
TEXT("SOFTWARE\\mykey"),
0,
WRITE_DAC,
&hKey
);
if(lRetCode != ERROR_SUCCESS) {
printf("RegOpenKeyEx error! (rc=%lu)\n", lRetCode);
return RTN_ERROR;
}
if(!AllocateAndInitializeSid(
&securityid,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&pAdministratorsSid
)) goto cleanup;
AllocateAndInitializeSid(
&securityid,
1,
SECURITY_LOCAL_SYSTEM_RID,
0, 0, 0, 0, 0, 0, 0,
&pSystemSid
) ;
AllocateAndInitializeSid(
&securityid,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_POWER_USERS,
0, 0, 0, 0, 0, 0,
&pPowerusersSid
);
dwAclSize = sizeof(ACL) +
3 * ( sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) ) +
GetLengthSid(pSystemSid)
+GetLengthSid(pAdministratorsSid)
+GetLengthSid(pPowerusersSid);
pDacl=(PACL)LocalAlloc(0,dwAclSize);
if(pDacl == NULL) goto cleanup;
if(!InitializeAcl(pDacl, dwAclSize, ACL_REVISION))
goto cleanup;
if(!AddAccessAllowedAce(
pDacl,
ACL_REVISION,
KEY_ALL_ACCESS,
pAdministratorsSid
)) goto cleanup;
AddAccessAllowedAce(
pDacl,
ACL_REVISION,
KEY_READ,
pPowerusersSid
) ;
AddAccessAllowedAce(
pDacl,
ACL_REVISION,
KEY_ALL_ACCESS,
pSystemSid
) ;
if(!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION))
goto cleanup;
if(!SetSecurityDescriptorDacl(&sd, TRUE, pDacl, TRUE)) {
printf("SetSecurityDescriptorDacl error! (rc=%lu)\n",
GetLastError());
goto cleanup;
}
lRetCode = RegSetKeySecurity(
hKey,
(SECURITY_INFORMATION)DACL_SECURITY_INFORMATION,
&sd
);
if(lRetCode != ERROR_SUCCESS) {
printf("fail\n);
goto cleanup;
}
else printf("Success"); //i am getting success
bSuccess = TRUE; // indicate success
cleanup:
RegCloseKey(hKey);
RegCloseKey(HKEY_LOCAL_MACHINE);
if(pDacl != NULL)
HeapFree(GetProcessHeap(), 0, pDacl);
if(pSystemSid != NULL)
FreeSid(pSystemSid);
if(pAdministratorsSid != NULL)
FreeSid(pAdministratorsSid);
if(pPowerusersSid != NULL)
FreeSid(pPowerusersSid);
|
|
|
|
|
I want to get each node in a Tree in MFC.How to do?
|
|
|
|
|
What are talking about?
AFAIK MFC does NOT define a Tree class (There are, of course, CTreeView and CTreeCtrl ...)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
I am saying about CTreeCtrl only.
|
|
|
|
|
If you want to traverse the whole thing then you have to go recursive.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
T.RATHA KRISHNAN wrote: I am saying about CTreeCtrl only
As suggested you need to use recursion, with help of CTreeCtrl class's functions. Have look at CTreeCtrl::GetNextItem,CTreeCtrl::GetChildItem,CTreeCtrl::GetNextSiblingItem .
Prasad
MS MVP - VC++
|
|
|
|
|
Why it is not possible to Delete/Move files using ::DeleteFile() or ::MoveFileEx() (which are in C:\ or C:\Program Files) in Windows Vista?
|
|
|
|
|
What do you think about a GetLastError call?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
BeliefInMe wrote: Why it is not possible ...
It is, as long as the UAC allows it.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
In standard user, it says "Access Denied".
Any solution.
|
|
|
|
|
Ensure that you have appropriate rights for such an operation.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
im having problem with the code..
i want to print the information of node visited while approaching to goalnode..program is not checking any of the node specified and returns without any output.. code is linking properly, without any error or warning.. code is as follows:
#include "astar.h"
#include "math.h"
#include <iostream>
#include <stdio.h>
#define DEBUG_LISTS 0
#define DEBUG_LIST_LENGTHS_ONLY 0
using namespace std;
int NumofNodes=10;
int id=1 ;
double coordination[10][3]={{1,2,3},{14,26,38} ,{10,20,30}, {25,67,45},{35,47,55}, {36,56,54}, {44,56,89}, {32,34,56},{43,56,78}, {12,32,45}};
double GetX(int id)
{
return coordination[id][0];
}
double GetY(int id)
{
return coordination[id][1];
}
double GetZ(int id)
{
return coordination[id][2];
}
class MapSearchNode
{
public:
double x; // the (x,y,z) positions of the node
double y;
double z;
double id; // the index of the node
double g; // cumulative cost from s to this node
MapSearchNode() { x = y = z = 0; id = 0; g = NumofNodes;}
MapSearchNode( double px, double py, double pz, double pid, double pg) { x=px; y=py; z=pz ;id=pid; g = pg;}
double GoalDistanceEstimate( MapSearchNode &nodeGoal );
bool IsGoal( MapSearchNode &nodeGoal );
bool GetSuccessors( AStarSearch<MapSearchNode> *astarsearch, MapSearchNode *parent_node );
double GetCost( MapSearchNode &successor );
bool IsSameState( MapSearchNode &rhs );
void PrintNodeInfo();
};
bool MapSearchNode::IsSameState( MapSearchNode &rhs )
{
// same state in a maze search is simply when (x,y,z) are the same
if( (x == rhs.x) &&
(y == rhs.y) && (z == rhs.z) && (id == rhs.id))
{
return true;
}
else
{
return false;
}
}
void MapSearchNode::PrintNodeInfo()
{
cout << "Node position :" << x << y << z;
}
// the heuristic function that estimates the distance from a Node
// to the Goal.
double MapSearchNode::GoalDistanceEstimate( MapSearchNode &nodeGoal )
{
double xd = double( ( x - nodeGoal.x ) );
double yd = double( ( y - nodeGoal.y) );
double zd = double( ( z - nodeGoal.z) );
// return xd+yd+zd;
return (double)(sqrt((xd*xd) + (yd*yd) +(zd*zd) ));
}
bool MapSearchNode::IsGoal( MapSearchNode &nodeGoal )
{
if( (x == nodeGoal.x) &&
(y == nodeGoal.y) && (z == nodeGoal.z) && id == nodeGoal.id )
{
return true;
}
return false;
}
bool MapSearchNode::GetSuccessors( AStarSearch<MapSearchNode> *astarsearch, MapSearchNode *parent_node )
{
double parent_x = 0;
double parent_y = 0;
double parent_z = 0;
double parent_id = 0;
int i;
MapSearchNode NewNode;
if( parent_node )
{
parent_x = parent_node->x;
parent_y = parent_node->y;
parent_z = parent_node->z;
parent_id = parent_node->id;
}
for(i=0; i<NumofNodes; i++)
{
if( (parent_id != i))
{
NewNode = MapSearchNode(GetX(i), GetY(i), GetZ(i), i, NumofNodes);
astarsearch->AddSuccessor(NewNode);
}
}
return 0;
}
double MapSearchNode::GetCost( MapSearchNode &successor )
{
cout << GoalDistanceEstimate(successor);
return GoalDistanceEstimate(successor);
}
int main( int argc, char *argv[] )
{
AStarSearch<MapSearchNode> astarsearch;
unsigned int SearchCount = 0;
const unsigned int NumSearches = 1;
while(SearchCount < NumSearches)
{
// Create a start state
MapSearchNode nodeStart;
nodeStart.x = 1.0;
nodeStart.y = 2.0;
nodeStart.z = 3.0;
// Define the goal state
MapSearchNode nodeGoal;
nodeGoal.x = 12.0;
nodeGoal.y = 32.0;
nodeGoal.z = 45.0;
// Set Start and goal states
astarsearch.SetStartAndGoalStates( nodeStart, nodeGoal );
unsigned int SearchState = 0;
unsigned int SearchSteps = 0;
cout << "SearchState" << SearchState<< endl;
cout << "astarsearch.SearchStep()" << astarsearch.SearchStep() << endl;
cout << "searchng" << AStarSearch<MapSearchNode>::SEARCH_STATE_SEARCHING << endl;
cout << "succeeded " << AStarSearch<MapSearchNode>::SEARCH_STATE_SUCCEEDED << endl;
cout << " failed " << AStarSearch<MapSearchNode>::SEARCH_STATE_FAILED << endl;
if( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_SEARCHING )
{
SearchState = astarsearch.SearchStep();
SearchSteps++;
#if DEBUG_LISTS
cout << "Steps:" << SearchSteps << "\n";
int len = 0;
cout << "Open:\n";
MapSearchNode *p = astarsearch.GetOpenListStart();
while( p )
{
len++;
#if !DEBUG_LIST_LENGTHS_ONLY
((MapSearchNode *)p)->PrintNodeInfo();
#endif
p = astarsearch.GetOpenListNext();
}
cout << "Open list has " << len << " nodes\n";
len = 0;
cout << "Closed:\n";
p = astarsearch.GetClosedListStart();
while( p )
{
len++;
#if !DEBUG_LIST_LENGTHS_ONLY
p->PrintNodeInfo();
#endif
p = astarsearch.GetClosedListNext();
}
cout << "Closed list has " << len << " nodes\n";
#endif
}
if( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_SUCCEEDED )
{
cout << "Search found goal state\n";
MapSearchNode *node = astarsearch.GetSolutionStart();
#if DISPLAY_SOLUTION
cout << "Displaying solution\n";
#endif
int steps = 0;
node->PrintNodeInfo();
for( ;; )
{
node = astarsearch.GetSolutionNext();
if( !node )
{
break;
}
node->PrintNodeInfo();
steps ++;
};
cout << "Solution steps " << steps << endl;
astarsearch.FreeSolutionNodes();
}
if( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_FAILED )
{
cout << "Search terminated. Did not find goal state\n";
}
// Display the number of loops the search went through
cout << "SearchSteps : " << SearchSteps << "\n";
SearchCount ++;
}
return 0;
}
please help me
|
|
|
|
|