473,698 Members | 2,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"catching" a base class pointer as the derived class

FP
I have a function that returns a base class pointer as in:

baseClass<T>* FunctionA( );

As you can see the baseClass is templated. FunctionA is found in a
third templated class.

What I'm trying to do is on the other side of things "catch" the
returned value as the derived class. My call looks liked this:

object->derivedPoint er = FunctionA( );

The derived class is also templated with <typename T>

I've tried using the following casts with no luck:
static_cast<bas ePtr>(object->derivedPtr) = FunctionA( );
dynamic_cast<ba sePtr>(object->derivedPtr) = FunctionA( );
(basePtr)(objec t->derivedPtr) = FunctionA( );

I'm using .Net 2003

Any help or an online referenc to look at would be appreciated.
Jul 22 '05 #1
1 1478

"FP" <de*****@faithp aradigms.com> wrote in message
news:69******** *************** ***@posting.goo gle.com...
I have a function that returns a base class pointer as in:

baseClass<T>* FunctionA( );

As you can see the baseClass is templated. FunctionA is found in a
third templated class.

What I'm trying to do is on the other side of things "catch" the
returned value as the derived class. My call looks liked this:

object->derivedPoint er = FunctionA( );

The derived class is also templated with <typename T>

I've tried using the following casts with no luck:
static_cast<bas ePtr>(object->derivedPtr) = FunctionA( );
dynamic_cast<ba sePtr>(object->derivedPtr) = FunctionA( );
(basePtr)(objec t->derivedPtr) = FunctionA( );

I'm using .Net 2003


You explaination isn't very clear, its usually better to post code than try
to describe code. However the following works for me, it's my best attempt
at reproducing your situation from your description.

template <class T>
class Base
{
};

template <class T>
class Derived: public Base<T>
{
};

template <class T>
class X
{
public:
void func()
{
Derived<T>* ptr = static_cast<Der ived<T>*>(funct ionA());
}
Base<T>* functionA()
{
return new Derived<T>();
}
};

int main()
{
X<int> x;
x.func();
}

john
Jul 22 '05 #2

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

Similar topics

2
1578
by: Sakharam Phapale | last post by:
Hi All, I am working on a project, where maximum operations carried out on Files and multi-dimensional arrays. Since array data is huge application takes too much memory. My problem is, after few operations, toolbar on MDI from doesn't catch "Click" event. But it catch all other events like mouse leave etc.
1
981
by: Lars Netzel | last post by:
I need to capture some sort of a rowchange (or datasource row change) and what I need in that Event is info from the row I came from not the row I'm changing to... a tricky for me.. I have no idea of what Object I should be looking for events for. Best Regards /Lars
2
1731
by: Anders Borum | last post by:
Hello! I was looking at marking objects with a changed state, once properties have been changed. The reason behind this is, that I would like to enlist such objects for processing in a transaction. The example below illustrates a sample pattern, which is fine when exposing simple value types. However, when exposing reference types, it becomes really hard (if not
11
11168
by: Ron L | last post by:
I have a barcode scanner which uses a "keyboard wedge" program so that the data it scans comes through as if it was typed on a keyboard. I am trying to have the data in the barcode be displayed in a text box. I know that there are certain control characters embedded in the data that I want to display substitutions for in the text box, for instance I want to replace ASCII character 04 with the string "<EOT>". I have tried doing a simple...
18
11843
by: Martin Jørgensen | last post by:
Hi, Today I got a really strange problem... I've made myself a data-file and I read in data from that file.... When I read something like this line: 03 04 05, 00 04 01, 05 03 07, 08 03 00, 09 06 03 ... etc. with something like scanf("%i %i %i, ", &var1, &var2, &var3);
0
5012
by: Ubiquitous | last post by:
Is there a way to catch these exceptions when thrown by PL/SQL? I get them on occasion and apparently the "WHEN OTHER" clause of my final EXCEPTION region does not catch it, causing my script to quit ungraciously.
3
5169
by: Robert Inder | last post by:
I am struggling to catch kestrokes within an Internet Explorer 6 window. My window happens to be displaying three frames, though I suspect a similar problem would arise with a single document. The "<body.." tag in each frame includes an "onKeyPress" handler to catch and act on key presses. And if I focus the window by clicking on the content of one of the documents, keystrokes are sent to the handler on its "<body..." tag.
0
1538
by: Bob Arn | last post by:
Is there a way to redirect on "file name too long" errors? I'm using mod_rewrite to handle all unknown urls with an error page. That's not working for this error. Apparently the "file name too long" error occurs before mod_rewrite is invoked. Setting up an ErrorDocument is also ignored, even though it looks to the user (and listed in access.log) as a 403 error, it's not a normal 403 error.
0
8603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7725
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...
1
6518
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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
4369
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
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
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
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.