|
You'll need to create a new array that is one size larger than the current one, copy the contents of the current one to the new one, delete the current one. Make sense?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
It makes sense, though it isn't very efficient. We are basically copying the data 2 times, first to a buffer, then back to the resized array. I was hoping for a better way of resizing an array, but this will suffice.
|
|
|
|
|
waldermort wrote: I was hoping for a better way of resizing an array, but this will suffice.
Basically, that's how the existing containers operate, with one important distinction: when they grow, they do it exponentially - not by one. Thus they reduce the number of copying at the expense of memory space.
Of course, once we have the move semantics in C++ (around 2010, I hope ) this will be a non-issue.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Nemanja Trifunovic wrote: Of course, once we have the move semantics in C++ (around 2010, I hope ) this will be a non-issue.
So you don't think we are going to be pushed towards the .NET way of things before then?
|
|
|
|
|
waldermort wrote: So you don't think we are going to be pushed towards the .NET way of things before then?
.NET is a platform, C++ is a programming language. I know quite a few people who make very nice salaries programming with languages like COBOL and Fortran.
But that's a bit OT, anyway.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
If you are using objects with simple types that need no destruction, you could use alloc() / realloc() . (I've long felt C++ should have a renew keyword, but it never happened.)
(EDIT: you could wrap these in a simple class to ensure proper destruction.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
|
I disagree--they overthought it; however I wrote a template class that contains a malloc/realloc that serves the same purpose.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I need to enumerate network resources from my service and for this i plan to use impersonation.
This is what i did.
LogonUser(username)
ImpersonateLoggedOnUser()
// do networking stuff
RevertToSelf()
when i perform these operations with username = Administrator, the networking code works fine but with
username = xxxx (which belong to the Administrators group), the networking code fails (GetLatError = 2).
What am i doing wrong here ?
As i see the username(xxxx) does not have a few access rights or privileges which the Administrator has to
enumerate network resources. any idea what are those rights or privileges ?
I tried with granting SeNetworkLogonRight to xxxx and it did not work.
any inputs will be helpful.
|
|
|
|
|
Hi Folks,
I am facing a little problem executing my program..
I am using an MFC APP Wizard Application, which was running fine untill I added a function[ Find() ] in my View class which uses a global function [ int getAngle() ].
I defined my global Function and Variable in a seprate header and use #include "Global.h" on top of my View Class (.h).
If i dont define this global function [ int getAngle() ] in "Global.h" and build my program the compiler complains about [ int getAngle() ] not declared and used in function [ Find() ].
But as soon i define the function [ int getAngle() ] in "Global.h" and build my program i get linker errors saying
"SimulationView.obj : error LNK2005: "int __cdecl GetMap(int,int)" (?GetMap@@YAHHH@Z) already defined in Simulation.obj
...
SimulationView.obj : error LNK2001: unresolved external symbol "int __cdecl getAngle(class MapNode,class MapNode)" (?getAngle@@YAHVMapNode@@0@Z)
Debug/Simulation.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe. "
Can anyone of u guys figure out whts the problem ???
Regards,
JinBaba
|
|
|
|
|
It looks like you are including Global.h in more than one spot. You need to add something like the following to it:
#ifndef _GLOBAL_H
#define _GLOBAL_H
int getAngle();
#endif
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hi David,
The thing is i am including "Global.h" in more than one spot.. but i have already followed the convention of
#ifndef _GLOBAL_H
#define _GLOBAL_H
#endif
but I still get the same problem.
Your Response needed..
Regards,
JinBaba
|
|
|
|
|
You might also employ the #pragma once directive.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hi David,
The thing is i am including "Global.h" in more than one spot.. but i have already followed the convention of
#ifndef _GLOBAL_H
#define _GLOBAL_H
#endif
but I still get the same problem.
Your Response needed..
Regards,
|
|
|
|
|
D3D 2D Texture(PNG File) How to set ColorKey
I have a PNG(or TGA or DDS) file,I want to create a texture with ColorKey dependendts on PNG's transparent color.
BOOL DoInit()
{
D3DPRESENT_PARAMETERS d3dpp;
D3DDISPLAYMODE d3ddm;
BYTE *Ptr;
#define PNG_WIDTH 256.0f
#define PNG_HEIGHT 256.0f
sVertex Verts[4] = {
{ 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f },
{ PNG_WIDTH, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f },
{ 00.0f, PNG_HEIGHT, 1.0f, 1.0f, 0.0f, 1.0f },
{ PNG_WIDTH, PNG_HEIGHT, 1.0f, 1.0f, 1.0f, 1.0f }
};
// Do a windowed mode initialization of Direct3D
if((g_pD3D = Direct3DCreate8(D3D_SDK_VERSION)) == NULL)
return FALSE;
if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
return FALSE;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = FALSE;
if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pD3DDevice)))
return FALSE;
// Create the vertex buffer and set data
g_pD3DDevice->CreateVertexBuffer(sizeof(sVertex)*4, 0, VERTEXFVF, D3DPOOL_DEFAULT, &g_pVB);
g_pVB->Lock(0,0, (BYTE**)&Ptr, 0);
memcpy(Ptr, Verts, sizeof(Verts));
g_pVB->Unlock();
// Load the texture map
D3DXCreateTextureFromFile(g_pD3DDevice, "Image1.png", &g_pTexture);
return TRUE;
}
|
|
|
|
|
Hi all,
can any1 refer me to code samples
on how to display preview of my web cam using Direct show??
couldn't find it anywhere...
thanks
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Hi,
i am modifying my partition table to create a new partition .But the system shows the newly created only after restarting the system. Is there any way to do this without restarting the system. I try BroadcastSystemMessage() with WM_DEVICECHANGE
but it is not working may be the parameters are not correct. Can anyone tell me how to use this function or some other function to refresh the sytem without restarting.
Thanks.
|
|
|
|
|
ashtwin wrote: I try BroadcastSystemMessage() with WM_DEVICECHANGE
but it is not working...
What is the error?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hi,
thanks for replying. I mean that though the function is returning 1 after execution but the system is still showing the same no of partitions even after the entry of newly created partition are inserted into the partition table.
I am using the function as
BOOL abc=BroadcastSystemMessage(BSF_POSTMESSAGE, BSM_ALLCOMPONENTS, WM_DEVICECHANGE, DBT_CONFIGCHANGED, 0);
Also i have tried with DBT_CONFIGCHANGED insted of DBT_CONFIGCHANGED but the result reamins the same.
Thanks.
|
|
|
|
|
When i compiled my program i got the error "Debug Assertion Failed".I referred for that error in msdn .But i cant understand it.can you tell me how can i delete this error.
|
|
|
|
|
keerthikaaa wrote: When i compiled my program i got the error "Debug Assertion Failed".
What line of what file?
keerthikaaa wrote: can you tell me how can i delete this error.
Not without knowing what is causing it.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Any time you get an assert look for the line that is asserting in your debugger. If the answer isn't immediately obvious after doing so more often then not you will find a comment describing what the problem is. If there isn't, and the assert is in code you manage, put one in.
Steve
|
|
|
|
|
|
look up CToolTipCtrl class in MSDN there are guided steps on how to use it....
good luck
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Add the LVS_EX_INFOTIP extended style and the control will show an infotip over items that are truncated.
If you want more complex infotips, handle LVN_GETINFOTIP .
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|