473,513 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Casting to a 'different' class...

nl
Hello,

I've got a question... I'm currently coding a software rasterizer...
I actually like to write my own matrix/vector classes, which I did, but
those classes don't work on the D3DX library of DirectX functions which I
also like to use... These only accept D3DXMATRIX, D3DXVECTOR2/3/4 etc
classes...

Using casting, is there any way to cast forward and backward from my own
classes to and from the microsoft d3dx classes? I'm thinking yes... almost
sure yes, but I'm not sure how to do it... so a code example would be
welcome...

Thx in advance...
Jul 22 '05 #1
8 1530
nl wrote:

Hello,

I've got a question... I'm currently coding a software rasterizer...
I actually like to write my own matrix/vector classes, which I did, but
those classes don't work on the D3DX library of DirectX functions which I
also like to use... These only accept D3DXMATRIX, D3DXVECTOR2/3/4 etc
classes...

Using casting, is there any way to cast forward and backward from my own
classes to and from the microsoft d3dx classes? I'm thinking yes... almost
sure yes, but I'm not sure how to do it... so a code example would be
welcome...


A cast is the moral equivalent of telling the compiler:
Shut up!

In your case the cast will shut up the compiler error messages.
But that won't help you very much. If the data structures are
incompatible, they are incompatible. If you shut up the compiler
or not.
--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #2
nl wrote:
Hello,

I've got a question... I'm currently coding a software rasterizer...
I actually like to write my own matrix/vector classes, which I did,
but those classes don't work on the D3DX library of DirectX functions
which I also like to use... These only accept D3DXMATRIX,
D3DXVECTOR2/3/4 etc classes...

Using casting, is there any way to cast forward and backward from my
own classes to and from the microsoft d3dx classes? I'm thinking
yes... almost sure yes, but I'm not sure how to do it... so a code
example would be welcome...


Something like this:
class MyMatrix
{
MyVector(const D3DXMATRIX &mat)
{ /* copy contents of D3DXMATRIX into this class for initialization */ }

MyMatrix& operator=(const D3DXMATRIX &mat)
{ /* copy contents of D3DXMATRIX into this class for assignment */
return *this;
}

operator D3DXMATRIX()
{ /* fill in a new D3DXMATRIX with data from this class, and return it
*/ }
}

This will allow you to cast your class to and from a D3DXMATRIX.

--
Unforgiven

Jul 22 '05 #3
Unforgiven wrote:
Something like this:
class MyMatrix
{
MyVector(const D3DXMATRIX &mat)
{ /* copy contents of D3DXMATRIX into this class for
initialization */ }


Uhm... the constrcutor must be called MyVector of course, not MyMatrix...
*sheepish grin*

--
Unforgiven
Jul 22 '05 #4
Unforgiven wrote:
Unforgiven wrote:
Something like this:
class MyMatrix
{
MyVector(const D3DXMATRIX &mat)
{ /* copy contents of D3DXMATRIX into this class for
initialization */ }


Uhm... the constrcutor must be called MyVector of course, not
MyMatrix... *sheepish grin*


God I did it again, it must be called *MyMatrix*. It's way to late at night
for me to be doing this obviously...
And it's spelled constructor of course, I'm on a roll today... a bad one,
unfortunately.

--
Unforgiven

Jul 22 '05 #5
"Unforgiven" <ja*******@hotmail.com> wrote:
Unforgiven wrote:
Unforgiven wrote:
Something like this:
class MyMatrix
{
MyVector(const D3DXMATRIX &mat)
{ /* copy contents of D3DXMATRIX into this class for
initialization */ }
Uhm... the constrcutor must be called MyVector of course, not
MyMatrix... *sheepish grin*


God I did it again, it must be called *MyMatrix*. It's way to late at

night for me to be doing this obviously...
And it's spelled constructor of course, I'm on a roll today... a bad one,
unfortunately.

--
Unforgiven


You are forgiven ! :-)

David F
Jul 22 '05 #6
David Fisher wrote:
You are forgiven ! :-)


It may be hard to believe, but in 4 years using this name on Usenet you're
only the second person ever to make that joke. ^_^

--
Unforgiven

Jul 22 '05 #7
Unforgiven wrote:
David Fisher wrote:
You are forgiven ! :-)


It may be hard to believe, but in 4 years using this name on Usenet
you're only the second person ever to make that joke. ^_^


You are forgiven!

Am I added as number 3 now to the list? Do I win something? :-)

Jul 22 '05 #8
In article <br*********@news3.tilbu1.nb.home.nl>, no*@listed.com says...

[ ... ]
Using casting, is there any way to cast forward and backward from my own
classes to and from the microsoft d3dx classes?


I'm not sure about "forward and backward", but it's certainly possible
to support conversion between the two types. Normally, you'll want to
support conversion from their type to yours by writing a ctor that takes
an object of their type as a parameter.

Conversion from their type to yours is done by writing a cast operator
in your class that does whatever is needed to covert your data to their
format. A really simple case could be done like this:

class Integer {
int val;
public:
Integer(int init) : val(init) {}

operator int() { return val; }
};

This supports implicit conversions from int to Integer via the ctor, and
from Integer to int via the cast operator. In your case, it sounds like
the conversion may easily be more complex, but from the sound of things,
I'm guessing you already know about how to get the data from one to the
other so I'll leave that alone for now (besides, it probably wouldn't be
topical here anyway).

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3443
by: Jacob Jensen | last post by:
This question has probably been asked a million time, but here it comes again. I want to learn the difference between the three type cast operators: static_cast, reinterpret_cast, dynamic_cast. A...
3
1672
by: Kurt | last post by:
i just can't figure out why something im doing is not working correctly.... public interface IInterface { int someProperty { get; set; }
44
2165
by: Agoston Bejo | last post by:
What happens exactly when I do the following: struct A { int i; string j; A() {} }; void f(A& a) { cout << a.i << endl;
1
281
by: Remco | last post by:
Hi, Let me try to simply explain my questions. I've created a portal site with different types of users, e.g. Portal Administrators and Normal Users. One base class SessionUser (has a enum...
8
2119
by: Michael | last post by:
Hi, I think my problem deals with class casting and inheritance. I want to deal with various Audio Formats, reading into memory for modification, working with it (done by different classes),...
3
2749
by: Tigger | last post by:
I have an object which could be compared to a DataTable/List which I am trying to genericify. I've spent about a day so far in refactoring and in the process gone through some hoops and hit some...
8
338
by: mfc | last post by:
Suppose I have a Cookie class and a Factory Class. There are many types of Cookies and maybe one or more Factories with a ProcessCookie Method. Suppose all the PutInBox method does is decide what...
5
2181
by: Ronald Raygun | last post by:
If I have the following class heirarchy: class A{ protected $m_type; function type(){return $this->m_type;} } class B extends A{} class C extends B{}
9
3453
by: Taras_96 | last post by:
Hi everyone, I was experimenting with static_cast and reinterpret cast #include <iostream> struct A1 { int a; }; struct A2 { double d; }; struct B : public A1, A2
19
1911
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post by:
I'm doing my c# more and more like i used to code c++, meaning i'm casting more often than creating an instance of objects. like : protected void gvOrderDetailsRowDataBound(object sender,...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7162
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5090
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3223
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1597
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.