|
what about changing this :
int doNothing(void) {
int j = 0;
tpteste w;
j = test(&w);
return 0;
}
|
|
|
|
|
I got lost at what exact point of the changes proposed you are.
The code now looks like this:
typedef struct {
int i;} tpteste;
int test (tpteste ** l)
{
*l = new tpteste[4];
l[0]->i = 99;
l[1]->i = 98;
l[2]->i = 97;
l[3]->i = 96;
return 0;
}
int doNothing(void)
{
int j = 0;
tpteste * w;
j = test(&w);
return 0;
}
When i try to change the code to the one you propodes i get the following error:
"error C2664: 'test' : cannot convert parameter 1 from 'tpteste *' to 'tpteste ** '"
|
|
|
|
|
here is the sample
typedef struct {
int i;
} tpteste;
void test (tpteste** l) {
*l = new tpteste[4];
l[0].i = 99;
l[1].i = 98;
l[2].i = 97;
l[3].i = 96;
}
void doNothing(void) {
tpteste* w;
test(&w);
}
notice the bolde lines in doNothing().
-- modified at 11:35 Wednesday 14th February, 2007
|
|
|
|
|
It shows the same behaviour. The "w" is still the same when it returns.
|
|
|
|
|
i changed my sample since i posted first. please retry
|
|
|
|
|
The code now is:
typedef struct {
int i;
} tpteste;
void test (tpteste** l) {
*l = new tpteste[4];
l[0]->i = 99;
l[1]->i = 98;
l[2]->i = 97;
l[3]->i = 96;
}
void doNothing(void) {
tpteste* w;
test(&w);
}
When it tryes to execute "l[2]->i = 97;" it stops with a adress violation.
|
|
|
|
|
Removing one level of complexity (the struct), take a look at:
void test( int *num )
{
num = new int;
*num = 5;
}
void main( void )
{
int *x = NULL;
test(x);
} You'll notice that when test() returns, x still has a value of NULL . Remember that if we want a function to be able to change something, it must be sent the address (i.e., pass-by-reference) not the value (i.e, pass-by-value). Pointers, too, have addresses and values. Therefore, you must send the address of the pointer.
One of the proper ways to do what you want is:
struct tpteste
{
int i;
};
void test( tpteste **l )
{
tpteste *t = new tpteste[4];
t[0].i = 99;
t[1].i = 98;
t[2].i = 97;
t[3].i = 96;
*l = t;
}
void doNothing( void )
{
tpteste *w = NULL;
test(&w);
}
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Man, it works!
When i pass the adress of the pointer, everything is fine. Not a surprise for you, but a great pleasure for me.
Now i'm gonna follow this way trying to make it work for a array of structures.
Thanks
void test (int **num)
{
*num = new int;
**num = 5;
}
int doNothing (void)
{
int * x = NULL;
test(&x);
return 0;
}
|
|
|
|
|
Man, thanks a lot!
I gonna buy a C++ book today, and i promisse i will (try to) never make a dummy question again.
|
|
|
|
|
Hi, modify your code like this:
//take the w's address into the func test()
//delete w Using "delete []w;" where you want
typedef struct
{
int i;
}tpteste;
int test(tpteste **l)
{
*l = new tpteste[4];
(*l)[0].i = 99;
(*l)[1].i = 98;
(*l)[2].i = 97;
(*l)[3].i = 96;
return 0;
}
int doNothing(void)
{
int j = 0;
tpteste * w;
j = test(&w); //w's address
return 0;
}
|
|
|
|
|
Is there anyway in visual c++ 6 to set a breakpoint in one thread and deubug, without other threads being stopped?
|
|
|
|
|
Open Visual Studio Settings, and reach the debugger options.
there's a parameter for this.
ps: what is you IDE ? if VS2003, 7th directory, 6th checkbox
ps2: please add a nickname to your account
|
|
|
|
|
Hi, I'm trying to modify and change and save a Visual C++ read-only file/project and I'm not sure how to go about doing this. The message I keep getting is:
"One or more od the source files (RemoteTestDlg.cpp) for class CRemoteTestDlg are read-only. Changes canot be made to read-only files!"
Please help. Thanks.
ibs
|
|
|
|
|
why on earth are your sources R/O, and why do you think you can modify a R/O file ?
remove the flag first in the file properties, then edit it
|
|
|
|
|
toxcct wrote: why on earth are your sources R/O, and why do you think you can modify a R/O file ?
remove the flag first in the file properties, then edit it
Here, any Files I forgot to check out of the source management system are read only.
And neither VS2003 nor VS2005 have any problems with unsetting the read-only flag on the fly: They ask, I click "Overwrite", and they overwrite without problem.
I have to be more alert when checking the files back in, but that's OK.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
It works fine now. I was trying to modify a downloaded visual c++ 6.0 sample program to build another application. Thanks a lot.
ibs
|
|
|
|
|
VC++ 6?
Because VS2003 as well as VS 2005 ask whether to remove the write-protection.
Did you copy them from a CD? Some burn-progs make all files on CD write protected and theis gets copied with the fiels.
You can simply use the explorer to remove the read-only-flag.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
I have a bitmap that is mainly black with some white pixels on it. This bitmap is updated continuously. I want to some how create an effect that can produce a sort of trail from the bitmaps using only GDI. An effect simerlar to what you see in wmp visualizations.
Any ideas?
|
|
|
|
|
Im in a C++ MFC visual studio 6.0 workspace. i have a float, which i need to round, both mathematically and string wise..
For example mathematically this;
0.306-> 0.31
0.99-> 1.00
and string wise;
0.12000000 -> 0.12
12.0000000 -> 12
Ive surfed around, but only found ones that dont remove unnecessary zeros, and dont work perfectly for all numbers..
The variable i have is a float, and im guessing its atof thats creating the extra zeros (which i have to use, or something equivalent)
rounding should be to 2dp, ie allways x.xx
any ideas?
thanks!
/Johannes
|
|
|
|
|
Johpoke wrote: For example mathematically this;
0.306-> 0.31
0.99-> 1.00
This is
int integer = (int)(0.306 + 0.5);
Johpoke wrote: and string wise;
0.12000000 -> 0.12
12.0000000 -> 12
Maybe boosts format library[^] can help you?
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
Johpoke wrote: 0.306-> 0.31
0.99-> 1.00
this is a matter of representation, so basically, printf() does it !
for the 2 questions btw, you can have a look here[^]
|
|
|
|
|
There's also the ceil() and floor() functions. It's really just a matter of trying each suggestion until you find the one that does just what you need.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Strings:
CString str;<br />
float f = 0.306;<br />
str.Format(_T("%.2g"), f);<br />
TRACE(_T("%s\n"), str);
Because I've used %g (instead of %f), 12.0 will be 12.
Numerics:
Take a look at this: http://www.codeproject.com/cpp/floatutils.asp[^]
- Dy
|
|
|
|
|
Well, that's not very "generic" (what happens when you need to round at a higher precision?).
double Rounder(double fVal, int nPrecision)
{
nPrecision = __max(__min(16, nPrecision), 1);
double fEpsilon = pow(10, nPrecision);
double fResult = ( floor(fVal * fEpsilon + 0.5) / fEpsilon);
}
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Now, that seems good, but it does lots of weird things that i dont want, try setting f to, 299.99 or 31.2699
thanks!!
/Johannes
|
|
|
|