C ++:限制派生类中的方法访问(C++ : Restrict method access in derived class)
我有一个Message类的对象,可以编写并随后更新。 据我所知,MessageUpdate IS-A MessageWrite:
class MessageWrite { protected: void setVersion(int version_) {...} void setReceiveTime(int tmReceive_) {...} Message _msg; }; class MessageUpdate:public MessageWrite { //ONLY setVersionShould be accessible here, NOT setReceiveTime };
是否有方法访问级别和继承级别的组合可以帮助实现这一目标?
我知道MessageUpdate可以简单地成为基类,但是有一些问题:如果我想扩展消息类,它会导致菱形模式。 考虑:
class MessageUpdate {...}; class MessageWrite: public MessageUpdate {...}; //Now, while extending: class AdminMessageUpdate:public MessageUpdate {...}; class AdminMessageWrite: public AdminMessageUpdate, public MessageWrite //DIAMOND Pattern!!
我对继承理解的差距在哪里? 没有多重继承(如后面的代码片段所示),有没有完全不同的方法来实现这种逻辑?
I have an object of class Message, which can be written and subsequently updated. As far as I can see, MessageUpdate IS-A MessageWrite:
class MessageWrite { protected: void setVersion(int version_) {...} void setReceiveTime(int tmReceive_) {...} Message _msg; }; class MessageUpdate:public MessageWrite { //ONLY setVersionShould be accessible here, NOT setReceiveTime };
Is there a combination of method access level and inheritance level that can help achieve this?
I know that MessageUpdate can be simply made base class, but there's the rub: it leads to diamond pattern in case i want to extend the message class. Consider:
class MessageUpdate {...}; class MessageWrite: public MessageUpdate {...}; //Now, while extending: class AdminMessageUpdate:public MessageUpdate {...}; class AdminMessageWrite: public AdminMessageUpdate, public MessageWrite //DIAMOND Pattern!!
Where'e the gap in my understanding of inheritance? And is there any completely different way to achieve this logic without the multiple inheritance (as shown in latter code piece)?
原文:https://stackoverflow.com/questions/10074407
最满意答案
Maybe you are being affected by this bug of android Camera bug.
The workaround to which is proposed here Work around.
I hope it helps..
相关问答
更多-
iPhone:获取相机预览(iPhone: Get camera preview)[2022-04-01]
这个也工作得很好。 相机预览打开时使用它: UIImage *viewImage = [[(id)objc_getClass("PLCameraController") performSelector:@selector(sharedInstance)] performSelector:@selector(_createPreviewImage)]; 但据我发现,它会带来与下面的解决方案相同的结果,该解决方案需要对 ... -
使用内部SurfaceView创建自定义视图 正如@momo在他的解决方案中报告的那样( https://stackoverflow.com/a/21653728/2124387 ): public class CroppedCameraPreview extends ViewGroup { private SurfaceView cameraPreview; public CroppedCameraPreview( Context context ) { super( context ); ...
-
问题似乎在这里,你没有包括持有人的类型。 您需要将类型设置为SURFACE_TYPE_PUSH_BUFFERS 。 添加回调后使用下面的行 holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 所以你的构造函数应该如下所示 public Preview(Context context, Camera camera) { super(context); this.camera = camera; holder = getHo ...
-
相机预览在少数设备中显示黑屏,但在其他设备上工作正常(Camera Preview showing black screen in few devices but working fine on others)[2021-10-29]
您可以查看支持的预览尺寸列表: Camera.Parameters parameters = camera.getParameters(); ListsizeList = parameters.getSupportedPreviewSizes(); 如评论中所示,我猜测相机不支持表面视图的大小。 没有更多信息,很难说其他任何事情。 You can check the list of supported preview sizes: Camera.Parameters param ... -
你不能从相机预览表面获取绘图缓存。 您必须从glsurface读取像素,或获取帧。 看看这个例子: https : //stackoverflow.com/a/26303163/5690332 You cannot getDrawingCache from camera preview surface. You must read pixels from glsurface, or get frame. Look at this example: https://stackoverflow.com/a/26 ...
-
相机预览仍然是黑色(Camera preview still black)[2022-11-19]
也许你受到Android Camera bug的这个bug的影响。 此处提出的解决方法解决方法。 我希望它可以帮助.. Maybe you are being affected by this bug of android Camera bug. The workaround to which is proposed here Work around. I hope it helps.. -
合并相机预览与图像?(Merge Camera preview with a image?)[2024-02-03]
假设你已经有来自jpeg回调的byte[] data形式的图像。 将图像解码为可变位图: Bitmap photo = BitmapFactory.decodeByteArray(data, 0, data.length); photo = photo.copy(photo.getConfig(), true); 阅读叠加层: Bitmap overlay = BitmapFactory.decodeResource(getResources(), R.drawable.one); 在照片上绘制叠加层: ... -
如何在Android上制作分辨率独立的相机预览?(How to make a resolution independent camera preview on android?)[2021-06-03]
在1.6 sdk中,无法获得支持相机预览的尺寸。 有。 您可以在解析preview-size-values相机参数时获取它们。 String supportedSizesString = parameters.get("preview-size-values"); ListsupportedSizes = new ArrayList (); if (supportedSizesString != null && supportedSizesString.length() > 0) { ... -
这个示例通过openGL解决了我的问题。 截图 This sample solved my problem by openGL.Screenshots
-
Apple是否使用黑魔法来完成相机的预览方向?(Is Apple using black magic to accomplish camera's preview orientation?)[2021-05-23]
他们将预览视图添加到uiwindow,这就是它不旋转的原因。 我希望这能回答这个问题。 如果没有,我会继续浏览他们的源代码。 从源代码引用。 我们将视频预览视图设为窗口的子视图,并将其发送到后面; 这使得FHViewController的视图(及其UI元素)位于视频预览之上,并且还使视频预览不受设备旋转的影响 他们也加了这个 _videoPreviewView.enableSetNeedsDisplay = NO; 这可能使它不会响应 编辑:现在预览旋转,UI也一样,所以为了解决这个问题,您可以添加第二个 ...