|
It is possible to do this but there would be a lot of functions that would need to be overwritten. It would just be easier to explicitly cast each time a function is called.
|
|
|
|
|
You can't implicitly cast between pointers to objects to unrelated classes. The design of C++ is such that if you want to behave like a complete nutter and do nutty things you can but you have to do something that looks ugly in return.
If you're sure that the two classes are completely type compatible and you won't have any problems later[1] you could use a set of shim functions to hide the disgustingness somewhere else. Bit like a Dorianic portrait, your code looks beautiful but up in the attic...
So if you've got:
void some_function( A *a );
implement an overide:
void some_function( B *b )
{
some_function( reinterpret_cast<A *>( b ) );
}
Ideally what you should have done was implement a set of proxy classes between your platform specific code and the rest of your program, then you'd be just reimplementing a set of interfaces. The sort of hack you're trying to perpetrate might keep management sweet in the short term but in the long term you'll suffer with horrible code. You can't win when you fight a language's type system.
[1] Forgive me for sniggering, but the ammount of times I've heard that from so-called experienced software engineers when they've relied on the binary layout of a class only to have them condemned to using a particular compiler forever more...
|
|
|
|
|
[1] we're not relying on the binary layout of the classes, but on the fact that our classes are just wrappers that look exactly like our platform-specific classes, the only difference being that they have a different name.
As i mentioned before, writing a function override would be even more work than explicitly casting each time a function is called due to the fact that there are a lot of functions.
|
|
|
|
|
So you only use each function once?
I think I get your problem now. You just want to plonk in another class with a similar public interface as another one. There are two ways to get around this sort of problem:
- stick a proxy class in the way and implement this proxy in terms or A or B. You can then use a factory method or other pattern to instantiate the proxy in the right way
- use templates. Templates allow you to use objects with a common interface without regard for what class they are. So you could write:
template <typename T>
void do_something( T *t )
{
t->do_something_cool();
t->gasp_in_amazement_as_i_do_something_cooler();
}
Then you can use the function with any class that supports the two member functions used in the function. Inheritance is not what you need here.
Cheers,
Ash
modified on Thursday, June 17, 2010 4:59 AM
|
|
|
|
|
Hi!
Is there any type casting to convert from Pointer to reference? My function is expecting a pointer but I've a Reference. What to do?
|
|
|
|
|
T.RATHA KRISHNAN wrote: I've a Reference
What do you mean you have a reference ?
Anyway, if you have a variable and need to pass a pointer to a function, you can use the address of operator (& ) to get the address of your variable.
|
|
|
|
|
IrrlichtDevice* device = createDevice(EDT_SOFTWARE, core::dimension2d<u32>(800, 600), 16, false);
I've to pass the above device(pointer) as a reference to the following function:
CEGUI::IrrlichtRenderer& myRenderer = new IrrlichtRenderer(device);
The "IrrlichtRenderer" is a constructor which accepts only a reference not a pointer. I
can not modify the above constructor because it's not mine( a third party library).
Is there any way?
|
|
|
|
|
Well, it is the opposite of what you were saying in you first post. In that case, simply dereference the pointer:
CEGUI::IrrlichtRenderer& myRenderer = new IrrlichtRenderer(*device);
|
|
|
|
|
Hi All,
I am new to this forum. I am struggling with the following bug.
I am working with a CEdit control. programmatically i am changing the value of the RTL reading order menu item value on the CEdit control. Following is the code i am using.
void CGMTextBoxCtrl::SetRightToLeft(BOOL bNewValue)
{
if (bNewValue)
{
m_ulExtendedStyle &= ~WS_EX_LTRREADING;
m_ulExtendedStyle |= WS_EX_RTLREADING;
//long ulExtendedStyle = SetWindowLong(GetSafeHwnd(),GWL_EXSTYLE,WS_EX_RTLREADING);
}
else
{
m_ulExtendedStyle &= ~WS_EX_RTLREADING;
m_ulExtendedStyle |= WS_EX_LTRREADING;
//long ulExtendedStyle = SetWindowLong(GetSafeHwnd(),GWL_EXSTYLE,WS_EX_LTRREADING);
}
SetModifiedFlag();
RecreateControlWindow();
}
After executing this, the Right to left reading order option is getting checked when i set the value to true. But the text in the control remains LTR.
I tried with Send message. But that couldn't help me. Can anyone please let me know how to achieve this ASAP. its very urgent.
Thanks in advance,
Lucky
|
|
|
|
|
Hi ALL,
Me myself found the following solution. Posting it here to save your time if u r facing the same problem
long ulExtendedStyle = GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE);
if (ulExtendedStyle & WS_EX_RTLREADING)
{
if (!bNewValue)
SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE,(ulExtendedStyle ^ (WS_EX_RTLREADING|WS_EX_LEFTSCROLLBAR|WS_EX_RIGHT))); //516 DECIMAL = 204 HEX
}
else
{
if (bNewValue)
SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE,(WS_EX_RTLREADING|WS_EX_LEFTSCROLLBAR|WS_EX_RIGHT|ulExtendedStyle)); //29188 DECIMAL = 7204 HEX
}
Regards,
Lucky
|
|
|
|
|
i m working with open GL enviroment in visual C++. i have tried to load texture on circle. it is hapening but texture is copied again and again on a circle. i know that problum is in 'glTexCoord2d()'func. i couldnt get the exact coordinate of texture. can any ony help me?
here is the source code
#include <GL/glut.h>
#include <GL/gl.h>
#include <windows.h>
#include <math.h>
#include<stdio.h>
#include<iostream.h>
double frame;
float rot = 0;
const GLfloat DEG2RAD = 3.14159/180;
GLuint texture;
int refreshMillis = 10000;
GLuint LoadTexture( const char * filename, int width, int height )
{
GLuint texture;
unsigned char * data;
FILE * file;
file = fopen( filename, "rb" );
if ( file == NULL )
return 0;
data = (unsigned char *)malloc( width * height * 3 );
fread( data, width * height * 3, 1, file );
fclose( file );
glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height,GL_RGB, GL_UNSIGNED_BYTE, data );
free( data );
return texture;
}
void FreeTexture( GLuint texture )
{
glDeleteTextures( 1, &texture );
}
void drawEllipse1(void)
{
GLint i;
GLfloat xradius=2;
GLfloat yradius=2;
glBegin(GL_POLYGON);
for (i=0; i < 360; i++)
{
float degInRad = i*DEG2RAD;
glTexCoord2d(-cos (degInRad) *xradius, - sin (degInRad) *yradius);
glVertex2f ( cos (degInRad) *xradius, sin (degInRad) *yradius);
}
glEnd();
}
void display()
{
glClearColor(0.0, 1.0, 1.0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity ();
glPushMatrix() ;
glEnable( GL_TEXTURE_2D );
glTranslatef(0,0,-17) ;
drawEllipse1() ;
glBindTexture( GL_TEXTURE_2D, texture);
glDisable( GL_TEXTURE_2D );
glPopMatrix() ;
glutSwapBuffers();
rot=rot+1.4;
}
void init (void)
{
texture = LoadTexture( "smiley1.raw", 640, 480);
}
void reshape (int w, int h) {
glViewport (0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
glMatrixMode (GL_MODELVIEW);
}
int main(int argc,char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutInitWindowSize (640, 480);
glutInitWindowPosition (100, 100);
glutCreateWindow("ellipse");
init();
glutDisplayFunc(display);
glutIdleFunc (display);
glutReshapeFunc (reshape);
glutMainLoop();
return 0;
}
|
|
|
|
|
You don't really explain what you want to achieve. What is exactly this texture and how should it be mapped on the circle ? Without knowing that, it will be difficult to help you.
|
|
|
|
|
I looked a bit more into your code and I guess your texture contains a circle which has to be mapped exactly on the circle you are drawing (the "simplest" case). Is that correct ?
If yes, your texture mapping is wrong. You have to map the texture coordinates from 0 to 1, so the center of the circle would be coordinate 0.5;0.5 in the texture.
Furthermore, the xradius and yradius shouldn't have any influence the coordinates in your texture (they are used to make your circle wider or smaller on the screen, thus they shouldn't modify how the texture is mapped).
With this said, you end up with something like this:
glTexCoord2d(0.5 + cos(degInRad)/2, 0.5 + sin(degInRad)/2);
One additional remark: you should call glBindTexture before you draw your ellipse. Here it is not really important because you have only one texture but otherwise, you would end up with another texture mapped on your circle.
|
|
|
|
|
It is happening because you are telling it to :
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
|
|
|
|
|
how can we just toggle all the bits in a variable using the shortest code?
Can anybody give me a sample code?
|
|
|
|
|
See reply under QA - don't post to multiple forums, it just duplicates work and annoys people.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
By using the ~operator:
int var1 = 0;
int var2 = ~var1;
|
|
|
|
|
Hi!
When I build my project, I got the following linker error:
error LNK2019: unresolved external symbol _D3DXMatrixTransformation@28 referenced in function "protected: void __thiscall CEGUI::Direct3D9GeometryBuffer::updateMatrix(void)const " (?updateMatrix@Direct3D9GeometryBuffer@CEGUI@@IBEXXZ) CEGUIDirect3D9GeometryBuffer.obj
How do I resolve this error?
|
|
|
|
|
It looks like there is a library directive missing form your linker process. Add a reference to the library that contains the D3DXMatrixTransformation function.
It's time for a new signature.
|
|
|
|
|
It means that you haven't linked with anything that contains the implementation of D3DMatrixTransformation. This either means that:
- You're not linking with a dependent library
- You haven't implemented a function that you should
If you wrote the class CEGUI::Direct3D9GeometryBuffer then it's probably the second. If it's someone else's class have a gawp through their documentation and find out what the dependencies are for that library and link it.
Cheers,
Ash
|
|
|
|
|
Hi everyone,
I want to do integration in MFC coding.
Is there any formulas for doing this one.
Actually i want to do the Ramp,Sin waves of formulas
for simulation of signals
Ramp wave required integration.
how to do integration in programming.
Any library or header files which will do integration.
|
|
|
|
|
Do you want to do the integration in real-time ? Is an approximation ok for you ?
There's an easy and quick way to make an integration, but it is an approximation (and the error margin depends on your sample rate and signal variation). If you remember that an integration of a signal is the calculation of the area under the curve of the signal, you can reach a good approximation by using an "average" method.
When you have two consecutive points of your signal, you will approximate the surface under those points by taking the average Y value and calculate the surface of the rectangle made by this Y and the X difference between the two points.
This looks like:
double dSurface = (Y2 + Y1)/2 * (X2 - X1);
You then need to add all these surface together to get an approximation of the total surface under the curve.
|
|
|
|
|
|
It's discrete data. Calculating the integral is really simple. If you can write a loop and use addition you will be fine.
|
|
|
|
|
hi,
im doing conversion of cstrings to std string.
In cstring mid function is available.
But i cant find the equalent function in std string...
can any one help me?
Thanx.
|
|
|
|
|