|
|
How to pass enum as default argument
I am having an issue with passing an enum as a default argument to a
class method. I have a class similar to
enum Method { a, b };
class A{
A();
void MyMethod(int i, Method m = a){
...
}
}
The compiler error I get says
error: default argument for 'Method m' has type '<unknown type>'
How can I use a default argument for an enum?
Thanks,
Jeremy
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
jeremit0 (72)
|
4/16/2008 3:44:46 PM |
|
On Apr 16, 5:44 pm, jeremit0 <jerem...@gmail.com> wrote:
> enum Method { a, b };
> class A{
> A();
> void MyMethod(int i, Method m = a){
> }
> };
>
> The compiler error I get says
> error: default argument for 'Method m' has type '<unknown type>'
> How can I use a default argument for an enum?
That is valid code. Perhaps your compiler has a bug?
--
Chris
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Chris
|
4/17/2008 3:49:38 AM
|
|
jeremit0 wrote:
> I have a class similar to
>
> enum Method { a, b };
>
> class A{
> A();
> void MyMethod(int i, Method m = a){
> ...
> }
> }
I guess the problem is in the 'similar to', because this code:
enum method { a, b };
void function( method m = a);
...actually compiles fine. Provide the real code, stripped down to the very
minimum.
Uli
--
Sator Laser GmbH
Geschäftsführer: Michael Wöhrmann, Amtsgericht Hamburg HR B62 932
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Ulrich
|
4/17/2008 3:59:52 AM
|
|
|
2 Replies
701 Views
(page loaded in 0.049 seconds)
|
|
|
|
|
|
|
|
|