|
-
September 20th, 2002, 01:37 AM
#1
A question on Knowing the data type
hi friends
I want to know the data type for a particular scenario . If anyone is aware please do reply.
example
class a
{
public:
func();
private:
char* ptr1;
wchar_t* ptr2;
};
void main()
{
a obj("Test");
char* ptr = func();
}
Explaination :
I have a class 'a' as shown above. The class can have any of the 2 pointers shown above allocated during its lifetime. The func() function in the class shown above and which is not implemented returns either a char* or a wchar_t* as per demanded by the users call to the function.
So if somebody can tell me how do i know what the user has asked for i.e. has he asked for a char* or a wchar_t*. Then knowing that i should return the specific pointer and the return type also should be dynamic.
Thanks
Paramjeet
-
September 20th, 2002, 02:34 AM
#2
There can only be one return type for a function but it can have parameters of different types.
Code:
...
void func (char*& result)
{
result = ptr1;
}
void func(wchar_t*& result)
{
result = ptr2;
}
...
char* ptr;
wchar_t* wptr;
a.func (ptr); // calls the char* version
a.func (wptr); // calls the wchar_t* version
Succinct is verbose for terse
-
September 20th, 2002, 04:11 AM
#3
That is what i know. But i wanted some way by the type can be known. I wanted to know what the user is asking for a char* or wchar_t*
Originally posted by cup
There can only be one return type for a function but it can have parameters of different types.
Code:
...
void func (char*& result)
{
result = ptr1;
}
void func(wchar_t*& result)
{
result = ptr2;
}
...
char* ptr;
wchar_t* wptr;
a.func (ptr); // calls the char* version
a.func (wptr); // calls the wchar_t* version
-
September 20th, 2002, 04:14 AM
#4
You know it because of the function that is called.
Code:
...
void func (char*& result)
{
//Type is char*
result = ptr1;
}
void func(wchar_t*& result)
{
//Type is wchar_t*
result = ptr2;
}
...
char* ptr;
wchar_t* wptr;
a.func (ptr); // calls the char* version
a.func (wptr); // calls the wchar_t* version
mfg Ungi
Music, music and VB. VB is like music: You never know how it is interpreted.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|