473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

"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->derivedPointer = FunctionA( );

The derived class is also templated with <typename T>

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

I'm using .Net 2003

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

"FP" <de*****@faithparadigms.com> wrote in message
news:69**************************@posting.google.c om...
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->derivedPointer = FunctionA( );

The derived class is also templated with <typename T>

I've tried using the following casts with no luck:
static_cast<basePtr>(object->derivedPtr) = FunctionA( );
dynamic_cast<basePtr>(object->derivedPtr) = FunctionA( );
(basePtr)(object->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<Derived<T>*>(functionA());
}
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
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...
1
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...
2
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...
11
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...
18
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...
0
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...
3
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. ...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...

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.