Hi All,
(I first posted this question on the csharp.general but got no response, and
since this NG is more active, so I repost it here)
I have two enum definitions from two different namespaces:
namespace ns1
{
public enum e1{
e1a, e1b ......
}
}
namespace ns2
{
public enum e2{
e1a, e1b,... e2a, e2b ...... (i.e. e2 extends the e1's enum)
}
}
Let say in ns1 I have created a array such that
e1[] e1Array=new e1[10];
If I passed the e1Array into a routine, is it possible to cast it into an n2
array, e.g.
e2 e2Array = (e1[]) e1Array. <--- not working.
Anyway get do this?
TIA. 2 2454
On 31 ene, 17:58, "John Smith" <j...@js.comwro te:
Hi All,
(I first posted this question on the csharp.general but got no response, and
since this NG is more active, so I repost it here)
I have two enum definitions from two different namespaces:
namespace ns1
{
public enum e1{
e1a, e1b ......
}
}
namespace ns2
{
public enum e2{
e1a, e1b,... e2a, e2b ...... (i.e. e2 extends the e1's enum)
}
}
Let say in ns1 I have created a array such that
e1[] e1Array=new e1[10];
If I passed the e1Array into a routine, is it possible to cast it into an n2
array, e.g.
e2 e2Array = (e1[]) e1Array. <--- not working.
Anyway get do this?
TIA.
Hi,
I think that you can't make a cast to enums
you should try to play with the numbers values of the enums, remember
that the elements of enums are internaly numbers
Thanks, Horacio.
Actually I was trying to do something like:
// bassically a switch wrapper
e1[] getSet()
{
if (wante1) // set somewhere
return getSetFrome1();
else
return getSetFrome2(); <--- that is my problem if I want to return the e2
array
in e1 namespace, could the cast be used?
}
Namespace e1ns
{
Public e1[] getSetFrome1()
{
Return new e1[x];
}
}
Namespace e2ns
{
Public e2[] getSetFrome2()
{
Return new e2[y];
}
}
"Horacio N. Hdez." <hn******@gmail .comwrote in message
news:11******** *************@h 3g2000cwc.googl egroups.com...
On 31 ene, 17:58, "John Smith" <j...@js.comwro te:
>Hi All,
(I first posted this question on the csharp.general but got no response, and since this NG is more active, so I repost it here)
I have two enum definitions from two different namespaces:
namespace ns1 { public enum e1{
e1a, e1b ......
} }
namespace ns2 { public enum e2{
e1a, e1b,... e2a, e2b ...... (i.e. e2 extends the e1's enum)
} }
Let say in ns1 I have created a array such that
e1[] e1Array=new e1[10];
If I passed the e1Array into a routine, is it possible to cast it into an n2 array, e.g.
e2 e2Array = (e1[]) e1Array. <--- not working.
Anyway get do this?
TIA.
Hi,
I think that you can't make a cast to enums
you should try to play with the numbers values of the enums, remember
that the elements of enums are internaly numbers
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Cgacc20 |
last post by:
I have a c struct from old code that cannot be modified and I am trying to
write a wrapper C++ class around it.
This class is often passed as a pointer to some c functions of a library and I
wanted to keep my new class transparent and compatible with those functions.
That is, when using the code, I should be able to do either:
oldVector xyz;
function( &xyz );
myVector xyz;
function( &xyz );
|
by: Suzanne Vogel |
last post by:
** Isn't the 'static_cast' operator the same as traditional type
casting? ie, Aren't the following ways of getting b1, b2 the same?
// 'Derived' is derived from 'Base'
Derived* d = new Derived();
Base* b1 = static_cast<Base*>(d);
Base* b2 = (Base*)d; // traditional type casting
Such is my understanding from code samples, my own uses, and this:
http://www.cplusplus.com/doc/tutorial/tut5-4.html
|
by: JohnK |
last post by:
under the covers is type casting in VB.Net the same as C# ?
myObject = CType(..,..) in VB.Net vs
myObject = (SomeClass)aObject
|
by: Roman Mashak |
last post by:
Hello, All!
Given the sample piece of code I have:
#include <stdio.h>
#include <string.h>
int main(void)
{
short int i, j;
|
by: René Nordby |
last post by:
Hi there,
Is there anyone that knows how to do the following?
I have a class A and a class B, that 100% inherits from class A (this means
that I don't have other code in class B, than the Inherit statement).
| |
by: Enekajmer |
last post by:
Hi,
1 int main()
2 {
3 float a = 17.5;
4 printf("%d\n", a);
5 printf("%d\n", *(int *)&a);
6 return 0;
7 }
|
by: dragoncoder |
last post by:
Consider the code
class A {
private:
int a;
};
int main(void) {
A x;
int* ptr = (int*)&x;
|
by: antonyliu2002 |
last post by:
Hi, guys,
I am using Visual Web Developer Express 2005 for my web application.
I wrote a simple class called MyTestClass.cs and put it in the App_Code
folder.
I compiled it to library from the DOS console using the command line
compiler csc and got a new file called MyTestClass.dll in App_Code.
|
by: Frederic Rentsch |
last post by:
Hi all,
If I derive a class from another one because I need a few extra
features, is there a way to promote the base class to the derived one
without having to make copies of all attributes?
class Derived (Base):
def __init__ (self, base_object):
# ( copy all attributes )
...
|
by: stmfc |
last post by:
in java, class types do not allow casting.
to convert one to other, there must be special methods (except inheritance)
does c++ allow class type casting? (except inheritance)
|
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...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
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...
| |