473,806 Members | 2,583 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 1545
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*******@hotm ail.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*********@ne ws3.tilbu1.nb.h ome.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
3484
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 good way to do this is by example. So I will give an example and please tell me what you think: I have a base class A with a virtual destructor, and a class B that is it inherits publicly from A and defines som extra stuff.
3
1686
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
2245
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 field UserType) and for each type of user a inherited class like SessionMasterUser and SessionNormalUser.
8
2140
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), and writing the result to disk afterwards. Therefore I have created some classes, e.g. WaveFileIO and AiffFileIO and MP3FileIO and AuFileIO for the In/Out operations.
3
2772
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 dead ends. I'm posting this to get some feedback on wether I'm going in the right direction, and at the same time hopefully save others from going through the process.
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 colour box to put the cookie into. But since the colour of the box depends on whatever Factory is boxing them (Different branding etc) the PutInBox method can't be in the Cookie class and has to be in the Factory class. The problem is pretty soon...
5
2199
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
3468
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
1956
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, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { switch (((Sale)e.Row.DataItem).SzPN) {
0
9719
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10373
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9192
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6877
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5683
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
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 we have to send another system
2
3852
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.