[ 44%] Built target opencv_features2d
[ 44%] Linking CXX shared library ../../lib/libopencv_objdetect.so
cd /tmp/opencv-20160725-28945-vyl9j5/opencv-2.4.13/macbuild/modules/objdetect && /home/usrname/.linuxbrew/Cellar/cmake/3.6.0/bin/cmake -E cmake_link_script CMakeFiles/opencv_objdetect.dir/link.txt --verbose=1
/usr/bin/g++-5 -fPIC -Os -w -pipe -march=native -fsigned-char -W -Wall - Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format- security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow - Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type- template-args -Wno-array-bounds -Wno-aggressive-loop-optimizations -fdiagnostics- show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 - ffunction-sections -DNDEBUG -DNDEBUG -L/home/usrname/.linuxbrew/lib -Wl,-- dynamic-linker=/home/usrname/.linuxbrew/lib/ld.so -Wl,- rpath,/home/usrname/.linuxbrew/lib -shared -Wl,- soname,libopencv_objdetect.so.2.4 -o ../../lib/libopencv_objdetect.so.2.4.13 CMakeFiles/opencv_objdetect.dir/src/cascadedetect.cpp.o CMakeFiles/opencv_objdetect.dir/src/datamatrix.cpp.o CMakeFiles/opencv_objdetect.dir/src/distancetransform.cpp.o CMakeFiles/opencv_objdetect.dir/src/featurepyramid.cpp.o CMakeFiles/opencv_objdetect.dir/src/fft.cpp.o CMakeFiles/opencv_objdetect.dir/src/haar.cpp.o CMakeFiles/opencv_objdetect.dir/src/hog.cpp.o CMakeFiles/opencv_objdetect.dir/src/latentsvm.cpp.o CMakeFiles/opencv_objdetect.dir/src/latentsvmdetector.cpp.o CMakeFiles/opencv_objdetect.dir/src/linemod.cpp.o CMakeFiles/opencv_objdetect.dir/src/lsvmparser.cpp.o CMakeFiles/opencv_objdetect.dir/src/lsvmtbbversion.cpp.o CMakeFiles/opencv_objdetect.dir/src/matching.cpp.o CMakeFiles/opencv_objdetect.dir/src/objdetect_init.cpp.o CMakeFiles/opencv_objdetect.dir/src/resizeimg.cpp.o CMakeFiles/opencv_objdetect.dir/src/routine.cpp.o ../../lib/libopencv_highgui.so.2.4.13 -ldl -lm -lpthread -lrt ../../lib/libopencv_imgproc.so.2.4.13 ../../lib/libopencv_core.so.2.4.13 -ldl -lm -lpthread -lrt -Wl,-rpath,/home/usrname/.linuxbrew/Cellar/opencv/2.4.13/lib
cd /tmp/opencv-20160725-28945-vyl9j5/opencv-2.4.13/macbuild/modules/objdetect && /home/usrname/.linuxbrew/Cellar/cmake/3.6.0/bin/cmake -E cmake_symlink_library ../../lib/libopencv_objdetect.so.2.4.13 ../../lib/libopencv_objdetect.so.2.4 ../../lib/libopencv_objdetect.so
make[2]: Leaving directory '/tmp/opencv-20160725-28945-vyl9j5/opencv-2.4.13/macbuild'
[ 44%] Built target opencv_objdetect
make[1]: Leaving directory '/tmp/opencv-20160725-28945-vyl9j5/opencv-2.4.13/macbuild'
make: *** [Makefile:164: all] Error 2
READ THIS: https://github.com/Linuxbrew/brew/blob/master/share/doc/homebrew/Troubleshooting.md#troubleshooting
If reporting this issue please do so at (not Homebrew/brew):
https://github.com/Homebrew/homebrew-science/issues
These open issues may also help:
public enum MaritalStatus
{
Single, Divorcee, Married
}
public class Person
{
protected int ID;
protected String FirstName;
protected String LastName;
protected MaritalStatus Status;
protected int Age;
public Person(int id,String firstname,String lastname,MaritalStatus status,int age)
{
ID=id;
FirstName=firstname;
LastName=lastname;
Status=status;
Age=age;
}
public String toString()
{
return System.out.println("ID: "+ID + " First Name: "+FirstName+" Last Name: " +LastName+" Marital Status: "+ StringStatus +" Age: "+Age);
}
}
答案 0 :(得分:2)
枚举类"中没有"错误。您在toString
中遇到问题(见下文)。您可能需要以下
public String toString() {
return "ID: "+ID + " First Name: "+FirstName+" Last Name: " +LastName+" Marital Status: "+ Status +" Age: "+Age;
}
问题:
System.out.println(…)
(它返回无效,它不会"打印并返回字符串")status
的字符串版本,只需在此上下文中使用status
(在字符串上使用+
)或在其他上下文中使用status.toString()
(其中{{1}期待的类型)。其他(无关)问题
String
,id
等)firstName
而非private
protected
)a = b
(例如final
,val
in other languages`)const
,SINGLE
)以下是您班级的(更多)正确版本:
MARRIED
P.S。我猜这不是生产代码,因为有一个名为public class Person {
private int id;
private String firstName;
private String lastName;
private MaritalStatus status;
private int age;
public Person(final int id, final String firstName, final String lastName, final MaritalStatus status, final int age) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.status = status;
this.age = age;
}
@Override
public String toString() {
return "Person{" +
"id=" + id +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", status=" + status +
", age=" + age +
'}';
}
}
的字段有点尴尬
答案 1 :(得分:0)
我可以看到两个编译错误,还有一大堆样式错误。
这一行:
return System.out.println("ID: "+ID + " First Name: "+FirstName+
" Last Name: " +LastName+" Marital Status: "+ StringStatus +
" Age: "+Age);
1)尚未声明变量StringStatus
。
1a)然后您将其更改为(String) Status
,这也是错误的,因为您无法将MaritalStatus
转换为String
。 (但你可以打电话给toString()
....)
2)println
方法是一种返回void
而不是String
的方法。
主要样式错误 1 是:
+
和=
等中缀运算符之前和之后放置一个空格。 ,
之前没有空格,之后没有空格。字段应为private
而不是protected
。
这不仅仅是风格。如果您没有将字段声明为private
,则子类或(更糟糕的)其他一些不相关的代码可能会干扰字段的值。这意味着您必须阅读更多代码才能了解在跟踪错误时可能发生的情况(例如)。使用private
有助于封装类型,从而使代码更易于阅读,更易于推理。
IMO,处理相同参数名称和字段名称的最佳方法(例如在构造函数中)是这样的:
public class Person {
protected int id;
public Person(int id) {
this.id = id; // Use 'this' to disambiguate the two meanings
// of the 'id' identifier.
}
}
1 - 不幸的是,一些“乐于助人”的人已经纠正了很多这样的问题,以使你的问题中的代码可读。请回头查看您最初发布的内容。