- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How can I control (e.g., disable) this C++ warning? I am using version 12.1.4 on OS X.
warning #2304: non-explicit constructor with single argument may cause implicit type conversion
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
/*
This warning is given under the -Weffc++ switch on code like the example below.
What it is telling you is that you should probably make this constructor "explicit".
If you don't then it can possibly be used in type conversions and in that case there
is no way to specify a value for the default argument.
So what are your options for avoiding this warning?
(1) Declare the constructor explicit
(2) Don't use the -Weffc++ option
(3) Disable this particular warning either with
#pragma warning (disable:2304)
inside the code or by using the command line option -diag-disable 2304
*/
class C {
public:
C(int, int j = 0);
};
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
/*
This warning is given under the -Weffc++ switch on code like the example below.
What it is telling you is that you should probably make this constructor "explicit".
If you don't then it can possibly be used in type conversions and in that case there
is no way to specify a value for the default argument.
So what are your options for avoiding this warning?
(1) Declare the constructor explicit
(2) Don't use the -Weffc++ option
(3) Disable this particular warning either with
#pragma warning (disable:2304)
inside the code or by using the command line option -diag-disable 2304
*/
class C {
public:
C(int, int j = 0);
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks! I'll be using the -diag-disable trick since this happens for me in C++ source files which don't belong to me that I'd prefer not to change.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page