Menu
Menu
DaniWeb
Log In
Sign Up
Read
Contribute
Meet
Search
Search
About 582 results for
typecast
- Page 1
Typecast
Programming
Software Development
13 Years Ago
by sdinu96
… as it is........so we have to
TYPECAST
on 17th line so how to
typecast
this and print the same output as…
Re: Typecast
Programming
Software Development
13 Years Ago
by nbaztec
This is plain stupid. 1. You don't wrap code in code tags 2. You double post. 3. What are you trying to achieve by assigning a (char*) an (int), which is illegal by the way 4. When you say 17th line did you expect me to count all the way when you didn't even bother to wrap this up in code tags? Your problem is still however not clear at all.
Re: Typecast
Programming
Software Development
13 Years Ago
by abhimanipal
What is the objective of your assignment ?
Trying to typecast without if statements
Programming
Software Development
15 Years Ago
by VernonDozier
… (object instanceof E) foo ((E) object); //
typecast
to type E else if (object instanceof F) foo… ((F) object); //
typecast
to type F else if (object instanceof G)… foo ((G) object); //
typecast
to type G else { // code to handle …
Re: Trying to typecast without if statements
Programming
Software Development
15 Years Ago
by VernonDozier
… your proposed solution) that there is no easy way to
typecast
in the situation I listed and if you don't… function the way it is? Is there no way to
typecast
in Java without hardcoding what you are type-casting to…
Re: Trying to typecast without if statements
Programming
Software Development
15 Years Ago
by Alex Edwards
… A> void doSomething(T type){ if(type instanceof [SpecialNeedClass]){ //
typecast
only for this type } // else if(...) // other specialized types else…
why typecast malloc ?
Programming
Software Development
12 Years Ago
by tubby123
Hi, I don't understand why we
typecast
malloc. For example, while creating a string/character array, we … allocated memory. All that's cool, but why do we
typecast
it to char*. What is the default data type of…
How to typecast this..............................
Programming
Software Development
13 Years Ago
by sdinu96
{ int i = 25789; char *p; .............. .............. printf("%d",*p); /* (*p) should give in printf*/ } dont assign p=i ............apart from this how we can
typecast
this program so that we can get interger value tp pointer p.............please help me this
Re: How to typecast this..............................
Programming
Software Development
13 Years Ago
by Ancient Dragon
…*/ } dont assign p=i ............apart from this how we can
typecast
this program so that we can get interger value tp…
function pointers typecast
Programming
Software Development
13 Years Ago
by DJSAN10
This is a part of code i read in a standard book.. f() {} . . . int *ip; ip=((int *)f); my question is..f gives d address of function..then wat is d need to
typecast
..??/
Re: function pointers typecast
Programming
Software Development
13 Years Ago
by DJSAN10
i thot tht ws quite implicit wat u said... newez sry fr nt putting it correclty... my doubt is simply whther is it necessary to perform d above
typecast
???
Re: function pointers typecast
Programming
Software Development
13 Years Ago
by Narue
[QUOTE]wat is d need to
typecast
..??/[/QUOTE] First and foremost, function pointers and object pointers are …
Managed C++ /CLI function CreateInstanceFromAndUnwrap typecast problem.
Programming
Software Development
12 Years Ago
by kaushik4study
…->GetValue(obj,nullptr);[/CODE] In part 1 i cant
typecast
the object with the class name because it is in…
Typecast reference
Programming
Software Development
16 Years Ago
by disc
[code] class MyControl : public BaseControl { } class Base { proctected: BaseControl &mControl; } class MyClass : public Base { public: MyClass( MyControl &control ); void ReadControl(); } MyClass::MyClass( MyControl &control ) :Base(control) { } void MyClass::ReadControl( void ) { MyControl &control =…
Re: Typecast reference
Programming
Software Development
16 Years Ago
by Ancient Dragon
Make it a pointer instead of a reference.
Re: Typecast reference
Programming
Software Development
16 Years Ago
by disc
[quote=Ancient Dragon;466016]Make it a pointer instead of a reference.[/quote] Sorry but that is not an option...
Re: Typecast reference
Programming
Software Development
16 Years Ago
by vijayan121
if MyControl is a polymorphic type: [code]// .... try { MyControl& control = dynamic_cast<(MyControl&>( mControl ) ; control.DoSomething(); } catch( const std::bad_cast& ) { // TODO: cast failed; handle it } // ...[/code] if not: [code]// .... MyControl& control = static_cast<(MyControl&>( mControl ) ; // …
Re: Typecast reference
Programming
Software Development
16 Years Ago
by disc
It was of the dynamic type ! vijayan121 thanks...
typecast problem
Programming
Software Development
11 Years Ago
by James19142
I need a way to do a cast without being returned a pointer to a new address but, the same address as the original. Something like this: derivedClass something_derived; baseClass* basePointer = &something_dervived; derivedClass* derivedPointer = static_cast <derivedClass*> (basePointer); /* my problem…
Re: typecast problem
Programming
Software Development
11 Years Ago
by deceptikon
Are you using multiple inheritance? Off the top of my head I don't recall if the C++ standard requires the base and derived object address to be the same for single inheritance, but it simply *cannot* be for multiple inheritance. There's no way to organize the structure of the object to make that happen. If you're using single inheritance then my …
Re: typecast problem
Programming
Software Development
11 Years Ago
by Ancient Dragon
Are you trying to do something like this? class base { public: base() {x = 0;} protected: int x; }; class derived : public base { public: derived() {x = 1;} protected: int y; }; void foo(base* b) { derived* d = static_cast<derived*>(b); // <<<< …
Re: typecast problem
Programming
Software Development
11 Years Ago
by James19142
@Ancient Dragon `derived* d = static_cast<derived*>(b); // <<<< this line` i need `d` to point to the same address as `b`, but `static_cast` returned a new address when i used it i need `base* b = /*derived*/d;` done backwards
Re: typecast problem
Programming
Software Development
11 Years Ago
by James19142
@deceptikon i'm using single inheritance
Re: typecast problem
Programming
Software Development
11 Years Ago
by Ancient Dragon
I think you need to use dynamic_cast instead of static_cast. Read the requirements for derived_class[ here](http://msdn.microsoft.com/en-us/library/c36yw7x9(v=vs.80).aspx) and [here](http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=179) As indicated in the second link if you use virtual functions in base class you may not need …
Re: typecast problem
Programming
Software Development
11 Years Ago
by mike_2000_17
> i need `base* b = /*derived*/d;` done backwards That is exactly what the `static_cast` does. Why do you assume that doing `base* b = d;` makes it so that `b` contains the same address value as `d`. In fact, there is no guarantee that it will. In a single inheritance scheme, it might be reasonable to expect that the address value isn't going …
Re: typecast problem
Programming
Software Development
11 Years Ago
by James19142
After reading the replies I redid the code and realized that all the C++ cast functions do exactly what I needed them to do in this case. I messed up in the pointer trail by grabbing an address from an array of similar name for the cast's parameter, and then noticed the change of addresses, my bad about that, should've revised my code before …
Re: Trying to typecast without if statements
Programming
Software Development
15 Years Ago
by Narue
>Is there a better way? Yes, design the class hierarchy such that you don't need to know the dynamic type of the object. Perhaps some form of strategy pattern would clean up that selection code.
Re: Trying to typecast without if statements
Programming
Software Development
15 Years Ago
by Alex Edwards
[QUOTE=Narue;711723]>Is there a better way? Yes, design the class hierarchy such that you don't need to know the dynamic type of the object. Perhaps some form of strategy pattern would clean up that selection code.[/QUOTE] Would an Adapter be overkill? I.E. [code=java] public class AdaptedA<T extends A> extends A{ private T …
Re: Trying to typecast without if statements
Programming
Software Development
15 Years Ago
by Ezzaral
That still involves runtime instanceof checks. I would agree with Narue's suggestion.
Re: Trying to typecast without if statements
Programming
Software Development
15 Years Ago
by Alex Edwards
You could use a State Machine, or State Pattern based on how many times an object has been encountered, or the State of an object can depend on the type of object it encounters... It may simplify things, but only if you can work out the different possible states of objects. I think this is the closest thing to a solution to your problem, though …
1
2
3
10
Next
Last
Search
Search
Forum Categories
Hardware/Software
Programming
Digital Media
Community Center
Latest Content
Newest Topics
Latest Topics
Latest Posts
Latest Comments
Top Tags
Topics Feed
Social
Forums
Top Members
Meet People
Community Functions
DaniWeb Premium
Newsletter Archive
Markdown Syntax
Community Rules
Developer APIs
Connect API
Forum API Docs
Tools
SEO Backlink Checker
Legal
Terms of Service
Privacy Policy
FAQ
About Us
Advertise
Contact Us
© 2024 DaniWeb® LLC