|
Alright say we have the following template class:
<br />
template <class T><br />
class Data {<br />
public:<br />
Data() : data(0) { } <br />
Data(T buff) : data(buff) { }<br />
void updateData(T buff) { data = buff; };<br />
T returnData() { return data; };<br />
private:<br />
T data;<br />
};<br />
is there anyway to find out which type was sent to the template argument T (such as int, char*, double, etc.)?
i would like to use an if or switch statement inside one of the classes functions such as:
<br />
void Data<T>::someFunction() {<br />
if (T == int) {
} else {
.. do this<br />
}<br />
}<br />
Thanks in advance for any help.
Carl
|
|
|
|
|
|
Is it possible if you could post a code fragment with an example of template specialization?
Thank you,
Carl
|
|
|
|
|
template <class T>
ref class Message
{
public:
void foo() { Console::WriteLine("Called Message<T>::foo()"); }
};
// Specialization
template <>
ref class Message<long>
{
public:
void foo() { Console::WriteLine("Called Message<long>::foo()"); }
};
int main(array<System::String ^> ^args)
{
Message<String^> ^stringMessage = gcnew Message<String^>;
Message<long> ^longMessage = gcnew Message<long>;
stringMessage->foo();
longMessage->foo();
return 0;
}
|
|
|
|
|
I have a little graphics demo to demonstrate a transformation class I'm doing and the Sleep() function seems to be working incorrectly. The program is a little tank that the user can move around with the keyboard. I use sleep on every cycle to try to slow down the frames per sec so the tank is controllable. If I omit Sleep() the program seems to run correctly, the tank is very quick and uncontrollable. I want to slow it to about Sleep(4) but when I use this it slows much more than 4 milliseconds per frame. From about Sleep(1) to Sleep(50) it's the same slow pace. Over 50 and it works correctly slowing in increments according to the number of milliseconds.
If anyone has had a similar problem or can just offer some advice it would be much appreciated.
I'll include a little code, if not enough please tell me.
I call Sleep() at the end of this function.
This is my function for glutIdleFunc(myIdle). It runs myIdle while the function has no imput.
void myIdle()
{
glClear(GL_COLOR_BUFFER_BIT);
if(upPressed == 1 && userBullet.getBulletCheck() == 0)
{
if(userBullet.getBulletCheck() == 0)
{
userBullet.setBulletStart(userTank.getBulletStart());
userBullet.setBulletCheck(1);
userBullet.setBulletDirection(userTank.getCurrentTurretDir());
}
userTank.drawTank();
}
if(wPressed == 0 && sPressed == 0 && aPressed == 0 && dPressed == 0 && rightPressed == 1 && leftPressed == 0)
{
userTank.rotateTurret(1);
userTank.drawTank();
}
/**In between these two code chunks is just more of the same, different operatios for different button presses.**/
if(sPressed == 1 && wPressed == 0 && dPressed == 1 && aPressed == 0 && rightPressed == 0 && leftPressed == 1)
{
userTank.rotateTurret(-1);
userTank.moveTankBck();
userTank.rotateBody(1);
userTank.drawTank();
}
userTank.drawTank();
if(userBullet.getBulletCheck() == 1 )
{
userBullet.moveBullet();
}
Sleep(4);
glutSwapBuffers();
}
-- modified at 19:05 Saturday 11th March, 2006
|
|
|
|
|
Sleep won't do what you are looking for because for so low sleep time, it is not accurate at all due to the non-real time behavior of the operating system. As windows is not a real-time OS, precision under 10 or 15 msec is unachievable. Instead of what you are doing, prefer another method: make a loop that will get the time and update your program every X msec:
int PastTime = GetTickCount();
while (true)
{
int TimeElapsed = GetTickCount() - PastTime;
if (TimeElapsed >= 30)
{
}
}
This code will update your program every 30 msec.
|
|
|
|
|
Correct me if i am wrong, but wouldn't it be better to use a timer instead of a while loop? As far as i am aware of while(true) it would mean active waiting and this will cost you valuable cpu time.
|
|
|
|
|
This while loop is used for games (and I suppose this was a game). The problem if you use a timer is that you will have some process time during the update of your game, and this processing time must not have an impact over the game. If you use a timer, the time between two updates will be the time of your timer plus the processing time, which can lead to varying timings (and if you need a specific time, to play animations for example, this will be a big problem).
Another method is to run the loop in continous and update the game everytime and passing the time elapsed.
|
|
|
|
|
Thanks for the replies. I kinda figured it out with a much less elegant solution.
I just ran a for loop from 1 to 1000000 so it slows down a bit. I'm gonna try to implement your method though because this is the way that games handle time I believe. It would probably make it easier to flesh out a game in the future. Thanks again.
-- modified at 19:29 Monday 13th March, 2006
|
|
|
|
|
zdog1 wrote: I just ran a for loop from 1 to 1000000 so it slows down a bit
Very very bad idea: the speed will then depend of the speed of the processor on which you run your game. For fast processors, your game will run really fast.
|
|
|
|
|
Hi guys~ I need to build a 3D map system that will accept 2 inputs from users (the current location and the destination user wants to go), by clicking, then the system will generate a path from the current location to the destination.
At first I planed to use OpenGL to do so....but I faced one problem. The exporter that I used can only extract the vertices of the model I built in 3DsMax, not included the texture mapping! I already done nice mapping in 3DsMax and I think it takes time to do mapping in OpenGL.(total up 15 buildings need to be mapped)
Therefore, I switch to VRML (because the 3DsMax can export the model to VRML file with texture mapped)but I found VRML is dead and not powerful at all. Then I switch to Java3D but I heard someone says this programming is dying and will run slow! The most powerful tools for 3D Graphics Application still belongs to--->OpenGL!! And now I stuck here~Time passed away quickly and I still not yet done my system!
I need some help from you guys and suggestions, advices from you all~Please...please help~~~~sob sob////
I more familiar with OpenGL if compared with Java3D and VRML(both I learned 3 days ago only,very unfamiliar~)
I wish to extract the model(with texture mapped) to OpenGl then I can quickly concerntrate on my system(my due date for this project is coming soon)
Thanks a lot!
|
|
|
|
|
Hi,
I want to expose a structure to C# code from the VC++ .
C# Code:
void AccessStructure()
{
structExample st;
st.x[0] = 4;
//Calling VC++ function
MyC++Func(st);
}
Structure declaration in vc++:
public ref struct structExample
{
public:unsigned char x[2];
public:int y;
};
VC++ function
void MyC++Func(structExample ^ stEx)
{
}
When Compiling the VC++ code i do get the following error
error C4368: cannot define 'x' as a member of managed 'structExample': mixed types are not supported
And also,
Is it possible to pass the structure as value type in the above case
Thanks in Advance
Regards
Sangeetha
|
|
|
|
|
This might help but certainly there is a more elegant way to achieve this:
public ref struct structExample
{
public:
structExample()
{
x = gcnew array<unsigned char>(arraysize);
}
array<unsigned char>^ x;
private:
literal int arraysize = 2;
};
|
|
|
|
|
Can anyone point me to some reading material or examples that would allow me to change a simple test menu program like this:
<br />
#include <iostream><br />
using namespace std;<br />
<br />
void main()<br />
{<br />
int iChoice;<br />
<br />
cout << "Choose one... " << endl << endl;<br />
cout << "1. First" << endl;<br />
cout << "2. Second" << endl;<br />
cout << "3. Third" << endl;<br />
cout << "4. Fourth" << endl << endl;<br />
<br />
cin >> iChoice;<br />
<br />
switch (iChoice)<br />
{<br />
case 1:<br />
if (iChoice == 1)<br />
cout << "First" << endl;<br />
break;<br />
case 2:<br />
if (iChoice == 2)<br />
cout << "Second" << endl;<br />
break;<br />
case 3:<br />
if (iChoice == 3)<br />
cout << "Third" << endl;<br />
break;<br />
case 4:<br />
if (iChoice == 4)<br />
cout << "Fourth" << endl;<br />
break;<br />
default:<br />
cout << "Not a valid choice." << endl;<br />
}<br />
}<br />
into a console application that uses the up and down arrows to make a selection inside of the menu box instead of typing in "1" and then "Enter"? I would like to be able to open the program with the list of options inside of a colored box and output the result into another colored box.
-- modified at 4:36 Friday 10th March, 2006
|
|
|
|
|
is your question .NET framework relative ?
|
|
|
|
|
I am working in the Visual Studio .net environment. No matter where I look, it seems I can't find any solid information on creating a simple DOS shell console application that uses keyboard events to make an up down selection menu.
|
|
|
|
|
I'd be surprised if there is such support in .NET for menus on a console window.
The way it was done in DOS is to output the hi-lighted menu item with inverted colors.
Mainly your program will wait for a key stroke and then pass the stroke when it arrives to a switch statement. The switch statements determines which menu items need to be re-output to the console screen - and with what colors (inverted/regular).
Note that you need to use positioning functions to be able to output text in the same spot with different colors.
I have not implemented this with the recent CRTs - so, I'm not sure what the exact function names are.
gmileka
|
|
|
|
|
If you need menu in doos shel, then you must use graphic ap0proach of programing and itersept cursor key.
or:
when you press up or down key, then clear scrren and selected menu shoud be diffrent color or higlitet
|
|
|
|
|
Hi,
i have an application which is running as a windows service,
it's purpose is to poll different sensors in a specific interval. No problem so far and with .Net memory profiler i was able to reduce the memory consumption drastically (allocs are almost -> 0 byte/s).
But now the downside, my idea was to present the sensors data on a ASP.NET page. My first thought was using a webservice to connect the windows service with the IIS. However after reading a comparison between Remoting vs. Webservices i decided to do remoting with an IPC channel.
So far so good, i have implemented a very light Remoting object, in addition i use the IPC channel and binary formatters. But when my application was finally running i discoverd that each remoting call will take around 8 KB of memory! Furthermore it allocates at least 178! Instances of differnt .Net classes for each call.
Imagine that i have to update my data on the IIS every second and addionally i have more than one sensor. This would mean for example that 5 Sensors would cost 40 KB or more memory per second, surely the garbage collector will take care of it. But how long will it take until i get in serious memory trouble (like Memory Pressure by the framework)? I saw that the garbage collector is triggered every 10 s in the current setup (without remoting it's between 45 min - 2h)
There are a couple of Questions:
1. Is it possible to reduce the memory consumption of .Net remoting? (i saw no difference between singleton & singecall)
2. Is remoting not the right choice for my task?
BTW: The service is written in C++/CLI, the logic and pages on the IIS are in C#.
I would really appreciate any help! If needed i could also publish some code to resolve the issue.
ThanX Tobias
the remoting Interface (each call of GetIndex costs 8KB):
public interface class IRemotingLink
{
ArrayList^ GetSensorKeys (void);
array <unsigned char>^ GetIndex (String^ pSensorGuid, unsigned char pIndex);
array <array <unsigned char>^>^ GetIndices (String^ pSensorGuid);
bool SetIndex (String^ pSensorGuid, unsigned char pIndex, array <unsigned char>^ pIndexContent);
};
-- modified at 2:34 Friday 10th March, 2006
|
|
|
|
|
|
You really think people here will do your homework for you ?
If you want an answer, post specific questions and post what you already did.
|
|
|
|
|
thk for u all...i knw my fault...
i cant do tat like tis...sorry for disturd u all....
very apologize wit it....
|
|
|
|
|
|
|
yup, typo...
|
|
|
|