473,698 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

compilation error

Slightly surprised that the following didn't compile

#inclue <algorithm>
enum { C = 10 };
int main()
{
char a[C];
std::fill_n(a, C, '\0');
}

Error message points to implementation of std::fill_n and complains that

unary '--' : '' does not define this operator or a conversion to a type
acceptable to the predefined operator

Essentially I think its complaining that it can't modify the value of the
enum C.

Is this correct? I expected the template to be instantiated with an int
which could be modified using operator--.

Replacing enum { C = 10 }; with const int C = 10; does compile.

John
Jul 19 '05
12 6119

"Pete Becker" <pe********@acm .org> wrote in message
news:3F******** *******@acm.org ...
John Harrison wrote:

"Pete Becker" <pe********@acm .org> wrote in message
news:3F******** *******@acm.org ...
John Harrison wrote:
>
> That's very strange because since enums are often used for ordinal types
you
> would think that if any arithmetic operators were to be defined then

it > would be ++ and --. Just an oversight I guess.
>

Nope, deliberate. We didn't want to require compiler writers to generate increment and decrement code for things like this:

enum flags { 0x01, 0x02, 0x04, 0x08, 0x10 };


OK I can buy that but then why define unary minus?


--, ++, +=, etc. all must create values of the same type as their
operand. Unary minus, as well as the rest of the arithmetic operators,
create integral values. Read about the "usual arithmetic conversions."


OK makes sense, in a twisted kind of way.

john
Jul 19 '05 #11

"Pete Becker" <pe********@acm .org> wrote in message
news:3F******** ******@acm.org. ..
John Harrison wrote:

"Pete Becker" <pe********@acm .org> wrote in message
news:3F******** *******@acm.org ...
John Harrison wrote:
>
> "Pete Becker" <pe********@acm .org> wrote in message
> news:3F******** *******@acm.org ...
> > John Harrison wrote:
> > >
> > > That's very strange because since enums are often used for
ordinal types
> you
> > > would think that if any arithmetic operators were to be defined
then it
> > > would be ++ and --. Just an oversight I guess.
> > >
> >
> > Nope, deliberate. We didn't want to require compiler writers to

generate
> > increment and decrement code for things like this:
> >
> > enum flags { 0x01, 0x02, 0x04, 0x08, 0x10 };
> >
>
> OK I can buy that but then why define unary minus?
>

--, ++, +=, etc. all must create values of the same type as their
operand. Unary minus, as well as the rest of the arithmetic operators,
create integral values. Read about the "usual arithmetic conversions."


OK makes sense, in a twisted kind of way.


Why do you call it twisted?


Your explanation makes perfect sense, and the current situation is not an
oversight at all (as I impudentally suggested) but a result of careful
consideration by the standard committee.

Nevertheless, from my point of view, it's still the case that the two
operators that it would make most sense for the standard to define behaviour
for (operator++ and operator--) have no behaviour defined. While operators
which are pretty meaningless for enum do have behaviour defined.

john
Jul 19 '05 #12
John Harrison wrote in news:bf******** ****@ID-196037.news.uni-berlin.de:
Your explanation makes perfect sense, and the current situation is not
an oversight at all (as I impudentally suggested) but a result of
careful consideration by the standard committee.

Nevertheless, from my point of view, it's still the case that the two
operators that it would make most sense for the standard to define
behaviour for (operator++ and operator--) have no behaviour defined.
While operators which are pretty meaningless for enum do have
behaviour defined.


If the behaviour was defined, like it is for int say, you couldn't
do this:

#include <iostream>
#include <ostream>

enum myEnum
{
A, B, C
};

myEnum operator+(myEnu m a, myEnum b)
{
int i = (int(a) + int(b)) % int(C + 1);
return myEnum(i);
}

myEnum &operator++(myE num &a)
{
int i = (int(a) + 1) % int(C + 1);
a = myEnum(i);
return a;
}

myEnum operator++(myEn um &a, int)
{
int i = (int(a) + 1) % int(C + 1);
myEnum b = a;
a = myEnum(i);
return b;
}
int main()
{
myEnum a, b, e;
a = B;
b = C;
e = a + b;

std::cout << int(e) << std::endl;

std::cout << int(++e) << std::endl;

std::cout << int(e++) << std::endl;

std::cout << int(e) << std::endl;

}
Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #13

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

Similar topics

6
2220
by: Joachim | last post by:
I made some project changes (which seems it doesn't help if I undo) which have created compilation error: " Server Error in '/PCSWebApp1' Application. -------------------------------------------------------------------------------- Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details
2
1802
by: James Zhuo | last post by:
Hi all I've been getting the following compilation error. I should explain the background of the project that i am taking over. This is a project that has been developed by someone else a while ago using dreamweaver, I am basically trying to migrate the project into a Visual Studio .NET environment before I start enhancing it. Any suggestions on where the source of error may be would be greatly appreciated.
0
1463
by: James Zhuo | last post by:
hi all I changed the name of the class LoginPage to a different name "LoginPageOne" But the same error gets generated with the Wiliam.Request.LoginPageOne. That pretty much leaves me clueless at this point. Please help Cheer
0
1512
by: Jie | last post by:
Does anyone know why I keep having the following error. I have to rebuild the solution every time I run it in design mode. thanks jie Server Error in '/ReapPortal' Application. ---------------------------------------------------------------------------- ---- Compilation Error
0
1273
by: John | last post by:
Hi, I've just rolled out a new version of an ASP.NET application. It runs fine on development and training servers, but on production get the following error when trying to access a page: Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details
2
1946
by: VB Programmer | last post by:
I created a ASP.NET app locally and it works great. Uploaded it to my server and I get this error when trying to view a page. Any ideas? Server Error in '/earlyalert3' Application. ---------------------------------------------------------------------------- ---- Compilation Error
2
6932
by: Kevin R. | last post by:
I have been ignoring this problem for a few weeks now, but it's becoming a bit annoying not to mention unproductive. Here it goes: I compile my project with no errors. Then after I debug/run it, I get the runtime error noted at the end of this message. If I re-compile (without any changes) and re-run, then my project will run OK. This behavior is very consistent. Another words, the only way I can run an ASP.NET application is if I...
6
2894
by: Plat | last post by:
I've Googled this for a while, to no avail. Hopefully someone can help me. Maybe I'm using the wrong terminology. Here's the scoop! Let's say I've got a simple *.ASPX page that has a syntax error. For example, broken.aspx might only contain the following line of code: <% Dim x as %> When I visit this page from my Web browser, I see all the helpful ASP.NET Server Error information, including:
0
1740
by: Stimp | last post by:
I've created an aspx page called HistoryManage.aspx. The page works fine on my local machine but when I load it off the web I get the following strange error... Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
1
2808
by: BSand0764 | last post by:
I'm getting an error that I can't seem to resolve. When I compile the Functor related logic in a test program, the files compile and execute properly (see Listing #1). However, when I incorporate the same logic within my simulation, the class that implements the functor logic has problems compiling. I get the following errors: -- Building myTest.cpp --
0
8685
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
8612
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
9171
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...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8905
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,...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
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
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.