|
Semion_N wrote: How can I check if the key exist?
Call Open() the way you did in your original post and check the returned error code. If the key does not exist Open() will fail with the return value of ERROR_FILE_NOT_FOUND.
Sorry it took so long to respond, I am not getting any reply emails from CP
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
pParams->add(amountId, (char *)&changeAmount, sizeof(changeAmount));
the second parameter looks strange...... haven't dealt with those before....
What's the function of that? [ (char *)&changeAmount ]
|
|
|
|
|
reinterpret_cast()
int x = 0
// 4 bytes on 32-bit
char *p = reinterpret_cast<char *="">(&x)
Kuphryn
|
|
|
|
|
im lost....... not to mention imma beginner
|
|
|
|
|
Actualy I knew one gentelman who casted CString* to CDocument* using reinterpret_cast. Great!
|
|
|
|
|
what is type of changeAmount?
|
|
|
|
|
its an integer
void ChangeBallVelocity(int changeAmount)
{
RTI::ParameterHandleValuePairSet* pParams = NULL;
pParams = RTI::ParameterSetFactory::create( 1 );
pParams->add(amountId, (char *)&changeAmount, sizeof(changeAmount));
rtiAmb.sendInteraction(velocityId, *pParams, NULL);
delete pParams;
}
This is very confusing....
What is pParams assigning?
class RTI_EXPORT ParameterSetFactory {
public:
static ParameterHandleValuePairSet* create(ULong count)
throw (
MemoryExhausted,
ValueCountExceeded,
HandleValuePairMaximumExceeded);
};
|
|
|
|
|
What's strange about it? The second parameter to the add() method is expected to be a char* . changeAmount is some other type, hence the cast.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Dave did you see address of what they are taking and what is going to happen later.
But reinterpret_cast solution was the best
|
|
|
|
|
Jay03 wrote: (char *)&changeAmount
This means that changeAmount is a variable. & turns it into a pointer. So, if changeAmount was an int, &changeAmount is an int *. Then whatever sort of pointer it is, it gets cast to a char *. Now, one has to presume this means it wasn't a char* to start with, but that this cast is valid.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
sorry to ask such a silly question but
Christian Graus wrote: So, if changeAmount was an int, &changeAmount is an int *.
So does this mean (char*) & changeAmount equivalent to : (char *) * int ChangeAmount
So this means, changeAmount was a pointer to an integer and is now changed to a pointer to a character?
|
|
|
|
|
No, it means that IF changeAmount was an int, then the & syntax turns it into a pointer, but that would then be an int *. A cast changes the type, in this case, to char *. That's what the & sytnax does, it returns the address of a variable. And a cast changes a variable type.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: & turns it into a pointer
how does & turn into a pointer.........
|
|
|
|
|
even Christian already gave you a valuable answer, here is another way to understand it.
in the expression (char*)&changeAmount , there are 2 operators called :
1. unary & usually called "address of" and used to get the address of changeAmount
2. (char*) is a cast operator, which explicits the cast of an address previously got with 1. into a char*
doing this changes the type of the pointer on the base address of changeAmount, so that it can be access each byte of that variable.
|
|
|
|
|
sorry to bother u but it makes sense to say changeAmount is an integer pointer and we want to cast it to a char pointer. But in our case changeAmount is NOT an integer pointer, its rather has the address of changeAmount (&changeAmount) ..... how can this be changed into a character pointer now.
it makes sense if it was like this:
(char*) int *changeAmount
pls get me running on the right track.. haha thanks
|
|
|
|
|
The function "add" has a second parameter that appears to take bytes as its type (an array of bytes actually). The & operator takes the address of a variable (that is, gives you a pointer to it) and the (char*) casts it to a charater pointer type. What it is doing is passing in the array of bytes for that variable (the size is passed as the third argument) to do something with them directly (e.g. transmit them over the network perhaps?).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
// hey here goes the program i have made pls help me out to find errors
#include <iostream.h>
//#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <process.h>
class sudoku{
int a[9][9][10],count;
public:
sudoku();
void initsudoku();
void redprob(int , int);
void dispsudoku();
void fillele(int , int );
void fillsudoku();
} ;
sudoku::sudoku()
{ int i , j ,k;
count=81;
cout<<"constructor";
for( i=1;i<=9;i++)
for ( j=1;j<=9;j++){
a[i][j][0]=99;
for ( k=1;k<=9;k++)
a[i][j][k]=0;
a[i][j][10]=9;
}
}
void sudoku::redprob(int i, int j )
{
int k,l,temp;
temp=a[i][j][0];
for ( k=1;k<=9;k++)
{
if (( k!=j) && (a[i][k][temp]!=99));
{ a[i][k][temp] = 99;
a[i][k][10]--;
if(a[i][k][10]==1)
fillele(i,k);
}
if (( k!=i)&&(a[k][j][temp]!=99));
{ a[k][j][temp] = 99;
a[k][j][10]--;
if(a[k][j][10]==1)
fillele(k,j);
}
}
cout<<"l"<<temp;
int="" h="i/3,g=j/3;
" for(="" k="0;k<3;k++)
" {="" l="0;l<3;l++){
" if((="" i!="h*3+k)||(j!=g*3" +l))
="" a[h*3="" +k][g*3="" +l][temp]="99;
" if="" (a[h*3="" +l][10]="=1)
" fillele(h*3="" +k,g*3="" +l);
="" }
="" }
="" }
="" void="" sudoku::initsudoku()
="" {
="" i,j,val;
="" char="" ch="y" ;
="" while(ch="='y')
" {
="" cout<<"enter="" the="" element="" ";
="" element\nrow="" no.";
="" cin="">>i;
cout<<"column no.";
cin>>j;
cout<<"enter value";
cin>>val;
if ((i<=9)&&(j<=9)&&(a[i][j][val]==0)&&(count<=0))
{
a[i][j][0]=val;
a[i][j][10]=0;
count--;
redprob(i,j);
}
else if (i>9)
cout<<"wrong row value";
else if (j>9)
cout<<"wrong column value";
else if (count<=0)
cout<<"already 81 elements have been identified";
else cout<<" you can not place this value here";
cout<<"enter any other element ";
cin>>ch;
}
}
void sudoku::fillele(int i, int j )
{ for( int k=1; k<=9;k++)
if( a[i][j][k] == 0){
a[i][j][0] = k;
a[i][j][10]=0;
count--;
redprob(i,j);
}
}
void sudoku::dispsudoku()
{ int i,j;
for( i=1;i<=9;i++)
{
for ( j=1;j<=9;j++){
if(a[j][i][0]>10){
cout<<" ";
}
else {
cout<
|
|
|
|
|
keshava shukla wrote: pls help me out to find errors
It's actually up to you to find the error(s). Narrow the problem down to just a few lines of code, and then you're bound to get lots of help. No one is going to wade through a bunch of code to find something that you should be finding.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Even if you posted this properly ( checked 'ignore HTML tags' ), no-one is going to fix your program for you. Work out which bit is not doing what you expect, post a relevant code snippet and ask specific questions.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Because VC8 don't alows to intit array of objects this way:
CElement elemArr[]={ {1, 2}, {3, 4}, {5, 6} };
I decided to convert it to that way, but I feel it not relible
CElement elemArr[]={ CElement(1, 2), CElement(3, 4), CElement(5, 6) };
Is it possible that elements of array will be self destroyed before elemArr?
class CElement
{
public:
CElement(int nA){m_nA = nA;};
CElement(int nA, int nB){m_nA = nA;m_nB = nB;};
virtual ~CElement(){m_nA = 0;m_nB = 1;};
virtual int Method(){m_nA = -1;m_nB = -3;return 0;};
protected:
int m_nA;
int m_nB;
};
|
|
|
|
|
definitely
a()
{
throw 0
}
try
{
a b
}
catch
{}
Kuphryn
|
|
|
|
|
No I talk only with situation with array, NOT just single object
void f(int nI)
{
CElement elemArr[]={ CElement(1, 2), CElement(3, 4), CElement(5, 6) };
int nJ = nI;
nJ++;
//Question elements off array could possible be destroyed right after declaration line?
//What is the scope/lifetime of my elements?
}
|
|
|
|
|
elements inside array are present
Kuphryn
|
|
|
|
|
Could you explain for how long?
Show line where distructor of CElement will be called?
void f(int nI)
{
CElement elemArr[]={ CElement(1, 2), CElement(3, 4), CElement(5, 6) }; //1
int nJ = nI; //2
nJ++; //3
}//4
I have guess it is ither 2 or 4?
But I want to know motivated answer.
|
|
|
|
|
Ok here is answer for myself
CElement elemArr[]={ CElement(1, 2), CElement(3, 4), CElement(5, 6) };
void OnBnClickedOk()
{
elemArr[1].Method();
elemArr[2] = CElement(7, 8); // here memcopy happens
//here destructor called of local element
}
//here dtor of global element called
|
|
|
|