|
OK. You're totally in the wrong place, this is the C++/CLI forum. The Visual C++ forum is the place for this.
int i = 0;
unsigned char j = i; // I think this will work, if not, then unsigned char j = (unsigned char)i; will
unsigned char * k = &j; // Now, j and k are the same thing, changing one will also change the other, as they are the same variable.
|
|
|
|
|
I have something like this
char **name;
name = new char*[3];
for(int i=0;i<3;i++)
{
name[i] = new char[256];
}
now how to delete name for no memory leaks
can anybody help me
thanks
abhi
|
|
|
|
|
I believe its:
<br />
delete [] name;<br />
since you dynamically created an array of char pointers.
Also, you will also have to delete each created char[256] beforehand.
<br />
for (int i; i < 3; ++i)<br />
{<br />
delete [] name[i];<br />
}<br />
<br />
delete [] name;<br />
Geo
-- modified at 6:03 Thursday 9th November, 2006
|
|
|
|
|
if I have something like this
void foo
{
char **name;
name = new char*[3];
for(int i=0;i<3;i++)
{
name[i] = new char[256];
}
}
and iam creating three objects of foo like foo foo1[3];
is the following is code?
for(int j =0;j<3;j++)
{
for (int i; i < 3; ++i)
{
delete [j] name[i];
}
delete [j] name;
}
if not then how to delete name
help me
thanks
abhi
abhi
|
|
|
|
|
First of all, foo looks like a function and not a class. So, you may need to find a good C++ Primer.
Memory management, especially with pointer-to-pointers, requires the programmer's special attention. Unless you are coding some performance critical code, STL would be a better route to go than to write "error prone" code with a limited knowledge of pointers and dynamic memory allocation.
See: http://www.codeproject.com/cpp/PointerArticle.asp[^]
void foo()
{
char **name;
name = new char*[3];
<br>
for (int i = 0; i < 3; ++i)
{
name[i] = new char[256];
}
<br>
<br>
for (int i = 0; i < 3; ++i)
{
delete [] name[i];
}
<br>
delete [] name;
}
Your code:
abhiramsss wrote:
if I have something like this
void foo
{
char **name;
name = new char*[3];
<br>
for(int i = 0; i < 3; i++)
{
name[i] = new char[256];
}
}
and iam creating three objects of foo like foo foo1[3];
is the following is code?
for(int j =0; j < 3; j++)
{
for (int i; i < 3; ++i)
{
delete [j] name[i];
}
<br>
delete [j] name;
}
if not then how to delete name
-- modified at 22:18 Thursday 9th November, 2006
|
|
|
|
|
I am putting together something and I need to get a list of active windows and the window that is on top, or in focus. How exactly could I go about this? I would imagine there is a specific function to call to for this. Does anyone know what it might be?
-- modified at 14:26 Tuesday 7th November, 2006
|
|
|
|
|
Did you want to do this in C++/CLI (.NET), or did you ask in the wrong forum ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Well I wanted to do it in C++ but if this C++/CLI is actually .NET then never mind. I suppose I should move it to Visual C++/MFC?
|
|
|
|
|
Yes.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I know how to read string values from Access db,
like:
CString strFields[5];
COleVariant varstring
for(field=0; field<5;field++)
{
recordset.GetFieldValue(field, varstring);
strFields[field]=V_BSTRT(&varstring);
}
then the string value from db. goes into strFields
But what if I know the strFields, and want write to update the db.
Does anyone know the adverse procedure?
|
|
|
|
|
This has nothing to do with "managed" development and you cross posted it into 3 forums and that subject is covered in several articles here on CodeProject. So to sum up.... stop posting garbage and do some work.
led mike
|
|
|
|
|
hi all!
I'd like to use Secure CRT memcpy_s(params); instead of old non-secure memcpy( params );
How to use it? where can I get all the necessary headers (and libs?) to use secure CRT in my proj?
thanks in advance,
d.coder
ps:
I use Microsoft Visual C++ .NET (develppment environment 2003 version 7.1.3088)
I've read about Secure CRT in this article:
"Employ Secure CRT Functions in Your C/C++ Applications"
http://www.codeguru.com/csharp/csharp/cs_misc/security/article.php/c11205/
|
|
|
|
|
You can't. It's only in VS2005. Yuo can write your own, it's kind of trivial to do so.
And, this is not a managed C++/CLI question.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: You can't. It's only in VS2005.
Hey CG,
While I am not 100% sure, I believe the sceure CRT was introduced in VC 2003, except that it didn't raise the warnings.
|
|
|
|
|
Yes, VS2003 had Strsafe functions! The replacement for strcpy was StringCbCopy for example. In order to use the Strsafe functions you had to do he following:
#define STRSAFE_LIB
#include <strsafe.h>
After doing the above, the compiler will view the older functions as deprecated, and the compilation will terminate with errors.
Geo
|
|
|
|
|
what are the base class variables can be accessible in below 3 derived classes ?
class base
{
public int i;
private int j;
protected int k;
}
class deriv1:public base
{
}
class deriv2:private base
{
}
class deriv3:protected base
{
}
-- modified at 8:10 Monday 6th November, 2006
Govindarajan,B.
|
|
|
|
|
Yes they are accessible,
in the first case
deriv1 class gets i,j,k in its public region.
in the second case
i,j,k become private in class deriv2
in the third case i,j,k become protected in class deriv3
but a class can access its variables, so all the three variables are accessible in all the three classes.
regards
Prashant Sabnekar
Regards
S.Prashant Sabnekar
|
|
|
|
|
Hi,
Thanks for your answer .
I have modified the varible's access specifier in base class now.
Before I forgot it.
I want the solution with this modification.
Thanks.
Govindarajan,B.
|
|
|
|
|
Do not listen to Prashant he doesn't know that he is talking about. Use the compiler to figure out the answers for your self.
led mike
|
|
|
|
|
Hi Mike,
The question is changed.
Earlier he kept everything public(i,j,k) so I said these are going to be public,
now he changed them to public, protected, & private.
My comment was actually to the previous question.
Prashant Sabnekar
Regards
S.Prashant Sabnekar
|
|
|
|
|
Prashant Sabnekar wrote: The question is changed.
Ah, well yeah that makes a difference.
led mike
|
|
|
|
|
Prashant Sabnekar wrote: deriv1 class gets i,j,k in its public region.
No, that is wrong.
Prashant Sabnekar wrote: so all the three variables are accessible in all the three classes.
Wrong again.
led mike
|
|
|
|
|
|
Hi Govindrajan,
First of all I want to say everybody that you have changed your question.
earlier you kept everything in public, now you have changed them.
Your solution is :
class deriv1 inherits variables i & k from class base.
i becomes public in class deriv1
k becomes protected in class deriv1
class deriv2 inherits variables i & k from class base.
i becomes private in class deriv2
k becomes private in class deriv2
class deriv3 inherits variables i & k from class base.
i becomes protected in class deriv3
k becomes protected in class deriv3
Regards
Prashant Sabnekar
Regards
S.Prashant Sabnekar
|
|
|
|
|
Actually, this is all mute since this is the C++/CLI forum, and C++/CLI only supports public inheritance.
|
|
|
|