473,654 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

abstract sealed & literal

ref struct XXX abstract sealed
{
literal int A = 5;
};

The definition above gives me the compiler warning "C4693: a sealed abstract
class cannot have any instance members 'A'". The equivalent definition is
perfectly legal in other CLR languages. For example in C#;

static class XXX
{
const int A = 5;
}

compiles without any error. Is there a way to specify CLR compatible consts
in a static class in C++/CLI?
Feb 17 '07 #1
18 2946
You haven't got the equivalent in C#.
That would be:
public abstract sealed class XXX
{
}
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
"Vedo" wrote:
ref struct XXX abstract sealed
{
literal int A = 5;
};

The definition above gives me the compiler warning "C4693: a sealed abstract
class cannot have any instance members 'A'". The equivalent definition is
perfectly legal in other CLR languages. For example in C#;

static class XXX
{
const int A = 5;
}

compiles without any error. Is there a way to specify CLR compatible consts
in a static class in C++/CLI?
Feb 17 '07 #2
And the error message you get in C# is: "an abstract class cannot be sealed
or static".
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
"David Anton" wrote:
You haven't got the equivalent in C#.
That would be:
public abstract sealed class XXX
{
}
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
"Vedo" wrote:
ref struct XXX abstract sealed
{
literal int A = 5;
};

The definition above gives me the compiler warning "C4693: a sealed abstract
class cannot have any instance members 'A'". The equivalent definition is
perfectly legal in other CLR languages. For example in C#;

static class XXX
{
const int A = 5;
}

compiles without any error. Is there a way to specify CLR compatible consts
in a static class in C++/CLI?

Feb 17 '07 #3
Hi,

Thank you for your reply. A "ref class XXX abstract sealed" class in C++/CLI
is compiled to ".class abstract sealed XXX" in MSIL which means "static
class XXX" in C#. So in your example you use the same keywords in C#, but
semantically they are different declarations.

Somehow the C++/CLI compiler does not allow me to define CLR constants in a
static class, which is normally allowed in CLR.

"Vedo" <ve**@vedo.comw rote in message
news:ug******** ******@TK2MSFTN GP02.phx.gbl...
ref struct XXX abstract sealed
{
literal int A = 5;
};

The definition above gives me the compiler warning "C4693: a sealed
abstract class cannot have any instance members 'A'". The equivalent
definition is perfectly legal in other CLR languages. For example in C#;

static class XXX
{
const int A = 5;
}

compiles without any error. Is there a way to specify CLR compatible
consts in a static class in C++/CLI?

Feb 17 '07 #4
A 'static class' in C# (new in C# 2005) just means that all members are
forced by the compiler to be static.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
"Vedo" wrote:
Hi,

Thank you for your reply. A "ref class XXX abstract sealed" class in C++/CLI
is compiled to ".class abstract sealed XXX" in MSIL which means "static
class XXX" in C#. So in your example you use the same keywords in C#, but
semantically they are different declarations.

Somehow the C++/CLI compiler does not allow me to define CLR constants in a
static class, which is normally allowed in CLR.

"Vedo" <ve**@vedo.comw rote in message
news:ug******** ******@TK2MSFTN GP02.phx.gbl...
ref struct XXX abstract sealed
{
literal int A = 5;
};

The definition above gives me the compiler warning "C4693: a sealed
abstract class cannot have any instance members 'A'". The equivalent
definition is perfectly legal in other CLR languages. For example in C#;

static class XXX
{
const int A = 5;
}

compiles without any error. Is there a way to specify CLR compatible
consts in a static class in C++/CLI?


Feb 17 '07 #5
Yes you're right. And the same concept in C++/CLI is supported through the
"abstract sealed" keyword combination.

For example the two classes below are exactly the same;

// C#
public static class XXX
{
public static int F()
{
return 1;
}
}

// C++/CLI
public ref class XXX abstract sealed
{
public:
static int F()
{
return 1;
}
};

Like the C# compiler, the C++/CLI compiler does not allow any instance
members in an "abstract sealed" (static) class. You are only allowed to
define static members. Now the problem is; in C# you can also define a
static class like;

public static class XXX
{
public const int x = 3;
...
}

but

public ref class XXX abstract sealed
{
public:
literal int x = 3;
....
};

fails with the compiler error "C4693: a sealed abstract class cannot have
any instance members 'x'", which is normally legal in MSIL (and in C# too).

Regards...

"David Anton" <Da********@dis cussions.micros oft.comwrote in message
news:91******** *************** ***********@mic rosoft.com...
>A 'static class' in C# (new in C# 2005) just means that all members are
forced by the compiler to be static.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
"Vedo" wrote:
>Hi,

Thank you for your reply. A "ref class XXX abstract sealed" class in
C++/CLI
is compiled to ".class abstract sealed XXX" in MSIL which means "static
class XXX" in C#. So in your example you use the same keywords in C#, but
semantically they are different declarations.

Somehow the C++/CLI compiler does not allow me to define CLR constants in
a
static class, which is normally allowed in CLR.

"Vedo" <ve**@vedo.comw rote in message
news:ug******* *******@TK2MSFT NGP02.phx.gbl.. .
ref struct XXX abstract sealed
{
literal int A = 5;
};

The definition above gives me the compiler warning "C4693: a sealed
abstract class cannot have any instance members 'A'". The equivalent
definition is perfectly legal in other CLR languages. For example in
C#;

static class XXX
{
const int A = 5;
}

compiles without any error. Is there a way to specify CLR compatible
consts in a static class in C++/CLI?



Feb 17 '07 #6
"Vedo" <ve**@vedo.comw rote in message news:ug******** ******@TK2MSFTN GP02.phx.gbl...
ref struct XXX abstract sealed
{
literal int A = 5;
};

The definition above gives me the compiler warning "C4693: a sealed abstract class cannot
have any instance members 'A'". The equivalent definition is perfectly legal in other CLR
languages. For example in C#;
An abstract class *cannot* be sealed in C#, in C++/CLI an abstract sealed class can only
have static members.

Please check the language specifications.

Willy.

Feb 17 '07 #7
Is this something you can use instead?

ref class XXX abstract sealed
{
static const int A = 5;
};
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
"Vedo" wrote:
Hi,

Thank you for your reply. A "ref class XXX abstract sealed" class in C++/CLI
is compiled to ".class abstract sealed XXX" in MSIL which means "static
class XXX" in C#. So in your example you use the same keywords in C#, but
semantically they are different declarations.

Somehow the C++/CLI compiler does not allow me to define CLR constants in a
static class, which is normally allowed in CLR.

"Vedo" <ve**@vedo.comw rote in message
news:ug******** ******@TK2MSFTN GP02.phx.gbl...
ref struct XXX abstract sealed
{
literal int A = 5;
};

The definition above gives me the compiler warning "C4693: a sealed
abstract class cannot have any instance members 'A'". The equivalent
definition is perfectly legal in other CLR languages. For example in C#;

static class XXX
{
const int A = 5;
}

compiles without any error. Is there a way to specify CLR compatible
consts in a static class in C++/CLI?


Feb 17 '07 #8
I want my code to be CLS compliant, but "static const" fields in C++/CLI are
marked with a special modopt attribute when compiled to MSIL which makes
them accessible only from the C++/CLI environment. I think I need to find an
other solution :) Thank you for your suggestions.

Regards...

"David Anton" <Da********@dis cussions.micros oft.comwrote in message
news:06******** *************** ***********@mic rosoft.com...
Is this something you can use instead?

ref class XXX abstract sealed
{
static const int A = 5;
};
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
"Vedo" wrote:
>Hi,

Thank you for your reply. A "ref class XXX abstract sealed" class in
C++/CLI
is compiled to ".class abstract sealed XXX" in MSIL which means "static
class XXX" in C#. So in your example you use the same keywords in C#, but
semantically they are different declarations.

Somehow the C++/CLI compiler does not allow me to define CLR constants in
a
static class, which is normally allowed in CLR.

"Vedo" <ve**@vedo.comw rote in message
news:ug******* *******@TK2MSFT NGP02.phx.gbl.. .
ref struct XXX abstract sealed
{
literal int A = 5;
};

The definition above gives me the compiler warning "C4693: a sealed
abstract class cannot have any instance members 'A'". The equivalent
definition is perfectly legal in other CLR languages. For example in
C#;

static class XXX
{
const int A = 5;
}

compiles without any error. Is there a way to specify CLR compatible
consts in a static class in C++/CLI?



Feb 18 '07 #9
Hi,

Thank you for your reply. You are right. I cannot have instance members in
an abstract sealed class. But are literals instance members? As far as I
know they are always considered to be part of the defining type. In other
words, they are always static members. The C++/CLI generated MSIL code for a
*non-abstract sealed* class with a literal integer field is;

..class public ... XXX
{
.field public static literal int32 i = int32(0x0000000 1)
}

As you see it is declared as a static field. But if I declare that literal
field in an abstract sealed class, the compiler gives me an error.

"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:ON******** ******@TK2MSFTN GP02.phx.gbl...
"Vedo" <ve**@vedo.comw rote in message
news:ug******** ******@TK2MSFTN GP02.phx.gbl...
>ref struct XXX abstract sealed
{
literal int A = 5;
};

The definition above gives me the compiler warning "C4693: a sealed
abstract class cannot have any instance members 'A'". The equivalent
definition is perfectly legal in other CLR languages. For example in C#;

An abstract class *cannot* be sealed in C#, in C++/CLI an abstract sealed
class can only have static members.

Please check the language specifications.

Willy.

Feb 18 '07 #10

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

Similar topics

33
3333
by: Chris Capel | last post by:
What is the rationale behind the decision not to allow abstract static class members? It doesn't seem like it's a logically contradictory concept, or that the implementation would be difficult or near-impossible. It seems like it would be useful. In fact, there's a place in my code that I could make good use of it. So why not? Chris
2
6729
by: Andrew Robinson | last post by:
I need to create a shared static field for use within a number of different classes. Which one should I be using or are they all really the same thing? public class Widget { private Widget() {} public static string DataField = string.Empty; } versus
6
3350
by: steve bull | last post by:
I created a usercontrol class, RGBColorSpace, which is derived from an abstract class, ColorSpace, but when I try to click on the design panel for the control I get an error message "Unable to create instance of abstract class ColorSpace". I never try to create a class ColorSpace and don't really want to create a regular class with virtual methods. Does anyone know why I am having this problem? The code seems to run fine and I can actually...
1
1971
by: JeffP | last post by:
Currently I have a user control which contain a <a href> link tag. I have a requirement to change the name property of the anchor tag to something like this: <a href="somepage.aspx" id"thislink" name="&lid=somename">Link</a> The problem is that when the aspx page renders this user control, the & character is converted to <literal>&amp;</literal>. So what I end with is: <a href="somepage.aspx" id"thislink"
10
3863
by: TJM | last post by:
Hi, Is it possible to have a method sealed and abstract at the same time? MSDN states clearly that this is not allowed for classes but it does not mention it for methods. I tried with a simple example and the compiler would not allow me to compile, however in a recent interview, I was asked this question and the interviewer claimed that this is used in certain situations! I am baffled! Thanks,
0
1248
by: Ken Varn | last post by:
I have the following code that I cannot get to compile. I get the error "A Sealed class cannot be abstract." public __value struct DVRAVIFileHeader : public ISerializable { double EventID; String *EventName; USHORT EventNum; String *EventType;
4
1784
by: Gert Kok | last post by:
The microsoft page http://msdn2.microsoft.com/en-us/library/9fkccyh4.aspx states: Remarks (nr 4) Virtual properties behave like abstract methods, except for the differences in declaration and invocation syntax.
3
2098
by: archana | last post by:
Hi all, I have created one sealed class having one constant. Can i access that constant of sealed class without creating object of that class. If yes will internally new object gets created. Or will it behave like static member which remains in memory throughotut applications' lifetime. Please correct me if i am wrong.
8
1718
by: puzzlecracker | last post by:
0) What is the convention name for derived classes? 1) If we implement methods in abstract class, do we still need to declare them as abstract? 2) Are we allowed to override methods in derived classes that are already implemented in abstract? 3) Are there a different accessibility levels when I inherit class, like (public, protected, private), like class A:public B? Thanks
0
8376
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, 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...
0
8290
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
8815
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, 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...
1
8489
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,...
0
8594
tracyyun
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...
0
7307
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...
0
5622
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
4149
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...
2
1596
bsmnconsultancy
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...

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.