|
I had a understanding that overriding the the function with variable argument list will result in to ambiguity. However when i tried to compile and run following code on VC++ 6.0, its working as expected :
/////////////////////////////////////
void Func1( int i, ... )
//Lets refer it as Func1VariableArg
{
// do something.
}
void Func1( int i, int j)
//Lets refer it as Func1FixedArg
{
// Do something.
}
class A
{
};
int main(int argc, char* argv[])
{
Func1(1, 1); // Func1FixedArg is called as expected.
Func1(1, "1"); // Func1VariableArg is called as expected.
A a;
Func1(1, a); // Func1VariableArg is called as expected.
// This is the spoil spot
Func1(1, 1.0)// here we would expect Func1VariableArg to
//be called as second argument is double, however compiler
// implicitely typecasts it to int and calls the Func1FixedArg.
// however a warning for the same is issued at complie time.
return 0;
}
/////////////////////////////////////
Some one has any comments about this practice. Do we have any issues in this practice ?, any comments from C++ language specifications on this.
Thanks -
Suyash
|
|
|
|
|
if the compiler can find a function which signature fits exactly to the argument types it receives, then there's no problem.
the ambiguity can arrise when the compiler has to do some implicit conversions...
in you case Func1(1, 1); results in calling void Func1(int, int) because literal numbers are firstly interpreted as int s.
i don't know the priorities of the compiler's implicit casts, but take this for instance :
Func1(1, 'a');
'a' is of type char , but no function Func1(int, char) exists, so it continues looking if this call fits another existing overload before casting some parameters.
only if the compiler makes some implicit casts an ambiguity can come, because the call can then fit several overloads...
|
|
|
|
|
I want to build an application that do something like this:
- give to an ordinary user more rights over a directory or a registry key that is not intend to have normally
- when the application ends the rights are retiered
The need is to hide certain information from the user
|
|
|
|
|
I am about to start using VC++ 2005 but according to the information on MS's website it doesn't not support creation of x64 code.
I found the following page which has instructions for building x64 apps with VS 6 and VS 2003. Would this also work with VS 2005 ?
http://www.devx.com/amd/Article/21313
Is it possible to create x64 code with VC++ 2005 ?
|
|
|
|
|
Just found this page on MS's website which looks promising
http://msdn2.microsoft.com/en-us/library/h2k70f3s.aspx
Anyone tried this with VC++ 2005 ?
|
|
|
|
|
|
I don't understand Microsoft's thinking that a profiler is such a high-level tool, with it only being included in the Team edition of VS 2005. A profiler is an essential part of any development suite to tighten any speed-critical code, but it seems Microsoft would rather everyone produced bloated inefficient software. Microsoft should have included a profiler with all editions of VS, except maybe the Express versions.
Compuware's DevPartner Profiler Community Edition worked OK with VS 2002 and 2003, but it doesn't say it's compatible with VS 2005.
Anyone know of a good profiler (preferably free or cheap) which works with VS 2005 (and in particular VC++ 2005) ?
|
|
|
|
|
Hi all:
Does anybody know how to pass an array as a reference parameter? When the procedure terminates, the content in the array are modified. For example:
<br />
float* ScaleVector(float *src, float deltaT){<br />
float *ret = new float[6*p.n];<br />
float *head = ret;<br />
<br />
for (int i = 0; i < p.n; i++){<br />
float vx = *(src++);
float vy = *(src++);
float vz = *(src++);
float ax = *(src++);
float ay = *(src++);
float az = *(src++);
*(ret++) = vx * deltaT + 0.5 * ax * deltaT * deltaT;
*(ret++) = vy * deltaT + 0.5 * ay * deltaT * deltaT;
*(ret++) = vz * deltaT + 0.5 * az * deltaT * deltaT;
*(ret++) = ax * deltaT;
*(ret++) = ay * deltaT;
*(ret++) = az * deltaT;
}<br />
return head;<br />
}<br />
Because this piece of code will be looped thousand times, it keeps on allocating memories to the temporary array *ret. This leads to the memory leaking of my system. How can I find a way to make a procedure to do the job by modifying the content of the array "*src" passed in instead of returning a separate array please??
Thanks in advance!!!
Asura
|
|
|
|
|
i'd better use stl containers for this :
void Foo(const std::vector<MyType>& constRefArray) {
}
|
|
|
|
|
Hi, just use the pointer to the buffer.
Make an destination buffer float* dest[6*p.n] and give it to the function like
you did with the source buffer.
void ScaleVector(float *src, float *dst, float deltaT){
for (int i = 0; i < p.n; i++){
float vx = *(src++);
float vy = *(src++);
float vz = *(src++);
float ax = *(src++);
float ay = *(src++);
float az = *(src++);
dst[i] = vx * deltaT + 0.5 * ax * deltaT * deltaT;
dst[i*6 + 1] = vy * deltaT + 0.5 * ay * deltaT * deltaT;
dst[i*6 + 2] = vz * deltaT + 0.5 * az * deltaT * deltaT;
dst[i*6 + 3] = ax * deltaT;
dst[i*6 + 4] = ay * deltaT;
dst[i*6 + 5]= az * deltaT;
}
}
But like V2.0 said stl-vectors are a better solution.
codito ergo sum
|
|
|
|
|
In addition to the above suggestion of using vectors etc, you could also use the old methods. Note that I haven't tested it.
//Also make sure that the src parameter is now large enough.
void ScaleVector(float *src, float deltaT)
{
for (int i = 0; i < p.n; i++)
{
float vx = src[i]; // velocity on x axis
float vy = src[i+1]; // y axis
float vz = src[i+2]; // z axis
float ax = src[i+3]; // acceleration on x axis
float ay = src[i+4]; // y axis
float az = src[i+5]; // z axis
src[i] = vx * deltaT + 0.5 * ax * deltaT * deltaT; // calculate the displacement at x axis
src[i+1] = vy * deltaT + 0.5 * ay * deltaT * deltaT; // y axis
src[i+2] = vz * deltaT + 0.5 * az * deltaT * deltaT; // z axis
src[i+3] = ax * deltaT; // added speed at x
src[i+4] = ay * deltaT; // y
src[i+5] = az * deltaT; // z
}
}
this is this.
|
|
|
|
|
I need to launch a GUI application from another application
that is running as a Window Service.
To do that I use the CreateProcess method. This is the code:
<br />
PROCESS_INFORMATION l_ProcessInfo;<br />
STARTUPINFO l_StartupInfo;<br />
<br />
ZeroMemory(&l_StartupInfo, sizeof(STARTUPINFO));<br />
<br />
l_StartupInfo.cb = sizeof(STARTUPINFO);<br />
l_StartupInfo.dwFlags = STARTF_USESHOWWINDOW;<br />
l_StartupInfo.wShowWindow = SW_SHOWMAXIMIZED;<br />
<br />
CreateProcess(NULL, <br />
l_cstrFileToLaunch.GetBuffer(0), <br />
NULL, <br />
NULL, <br />
FALSE,<br />
DETACHED_PROCESS,<br />
NULL,<br />
NULL,<br />
&l_StartupInfo,<br />
&l_ProcessInfo))
The problem is the following:
the GUI application is launched (CreateProcess returns nonzero and I can
see the new process running by task manager) but its windows is not shown
and I can't see its hinstance in the Windows Command bar.
Where is the problem ?
Can someone help me ?
thanks a lot !!!
|
|
|
|
|
Hi ilgale,
your code worked,
whats problem(I run NotePad) and this work
|
|
|
|
|
That code runs ok if executed by an application that runs normally...
but not if executed by an application that runs as a Window
Service.
I've registered an application as a Window Service and I've
started it by the Service Control Manager. In that case the
CreateProcess doesn't let the "child" application to show its window.
|
|
|
|
|
Will something like this help:
AttachThreadInput(
GetWindowThreadProcessId(
::GetForegroundWindow(),NULL),
[YourProcessId],TRUE);
SetForegroundWindow();
SetFocus();
AttachThreadInput(
GetWindowThreadProcessId(
::GetForegroundWindow(),NULL),
[YourProcessId],FALSE);
~RaGE();
|
|
|
|
|
Thanks a lot !!!
but.. what's the HWND object that I have to pass to
SetForegroundWindow and SetFocus functions ?
If I've well understood I've to run that code into the
Service that uses the CreateProcess but.. I need an HWND object to pass to that functions....
|
|
|
|
|
ilgale wrote: If I've well understood I've to run that code into the
Service that uses the CreateProcess
Yes sorry, I had to go away from my desk, so I fired up the post.
This is a snippet used to bring a dialog on the top of the Z-order, i thought it coudl work in your case. I do not exactely know how a service works, but I assume it is a normal Win application started differently. So I believe you must be able to get a HWND with GetSafeHwnd() from within the service.
~RaGE();
|
|
|
|
|
The problem is that the service in not a Win application,
it is a simple C++ program with a main, including MFC
functions. So I don't have an HWND object
I think the problem is in STARTUPINFO object settings...
|
|
|
|
|
I think the problem is that the service is not interactive. You should make it interactive if it is not already.
this is this.
|
|
|
|
|
|
|
Hello
I wanna create a Visual C++ program that encrypt a message and plit the ancrypted message into certain parts,and then the message will be recostructed by a certain amount of parts of the encrypted message.
|
|
|
|
|
For the encryption part, simply type encryption in the combo box on the up left of this page (under code project) and you'll find enough article to help you get a start at it.
For the splitting part, I would try and do a search about zip libraries: they used to provide file splitting algorithms.
~RaGE();
|
|
|
|
|
I am currently trying to complile programs which use the vmr9 direct show filter. Unfortunatly i get an error in MS Vis Studio .NET 2003 saying that it cannot locate the file vmr9.h .
I have installed the DirectX SDK (October 2005) and i cant find the files anywhere for download across the net.
Any ideas ?
Cheers
|
|
|
|
|
vmr9.h is in platform sdk.
-Saurabh
|
|
|
|