On 3/23/2016 11:36 AM, Bob Langelaan wrote:
> class myClass
> {
> const int i;
> };
>
> int main()
> {
> myClass a, b;
> a = b;
> }
>
> The code above generates 3 errors in MS VS 2015, all of which
> refer to "attempting to reference a deleted function"....
> ... it took me a while to find the issue the first time....
> ... students would be more likely to able to figure the issue
> on their own if the MS VS 2015 error messages were more
> illuminating.
This is yet another case where I find MS software bloody annoying.
Try Gnu's g++. While it is annoyingly silent about *some* errors
(see my post below about "initializing std::string to 0"),
it prints *lots* of warnings and errors for your code, including
a warning to the effect that "warning: non-static const member
‘const int myClass::i’ in class without a constructor":
%make const-member-test.exe DEBUG=1 PEDANTIC=1
Using pattern rule %.exe:%.cpp to compile const-member-test.cpp to const-member-test.exe:
g++ -I /rhe/include -pedantic -Wall -Wextra -Wfloat-equal -Wshadow -Wcast-qual
-Wcast-align -Wconversion -Winline -Wcomments -Wundef -Wunused-macros
-Wold-style-cast -Woverloaded-virtual -std=gnu++14 const-member-test.cpp
-L/rhe/lib -L/lib -lrh -lfl -ly -lm -lname -o /rhe/bin/test/const-member-test.exe
const-member-test.cpp:3:12: warning: non-static const member ‘const int myClass::i’
in class without a constructor [-Wuninitialized]
const int i;
^
const-member-test.cpp: In function ‘int main()’:
const-member-test.cpp:8:10: error: use of deleted function ‘myClass::myClass()’
myClass a, b;
^
const-member-test.cpp:1:7: note: ‘myClass::myClass()’ is implicitly deleted because
the default definition would be ill-formed:
class myClass
^
const-member-test.cpp:1:7: error: uninitialized const member in ‘class myClass’
const-member-test.cpp:3:12: note: ‘const int myClass::i’ should be initialized
const int i;
^
const-member-test.cpp:8:13: error: use of deleted function ‘myClass::myClass()’
myClass a, b;
^
const-member-test.cpp:9:4: error: use of deleted function
‘myClass& myClass::operator=(const myClass&)’
a = b;
^
const-member-test.cpp:1:7: note: ‘myClass& myClass::operator=(const myClass&)’
is implicitly deleted because the default definition would be ill-formed:
class myClass
^
const-member-test.cpp:1:7: error: non-static const member ‘const int myClass::i’,
can’t use default assignment operator
/rhe/maketail:198: recipe for target 'const-member-test.exe' failed
make: [const-member-test.exe] Error 1
--
Cheers,
Robbie Hatley
Midway City, CA, USA
perl -le 'print "\154o\156e\167o\154f\100w\145ll\56c\157m"'
http://www.well.com/user/lonewolf/
https://www.facebook.com/robbie.hatley