friend

Case Study: Polymorphism for Image Processing

ⅰ亾dé卋堺 提交于 2019-12-12 02:43:39
问题 I'm studying Digital Image Processing by myself and would be really grateful if somebody could comment whether polymorphism should be applied for this case or if there's a better class design. Basically, a 2D Filter/Kernel can be either: non-separable or separable . An important kernel operation is the convolution and the way to compute it, depends on the filter type. template < typename T > class CKernel2D{ public: //.... virtual CMatrix<T> myConvolution(const CMatrix<T> & input) = 0; //....

Is there a way to protect a class variable from being modified outside of a function

守給你的承諾、 提交于 2019-12-11 10:41:12
问题 I have a volume variable that I want to be protected from modification unless the person calls a certain function. Is there a way to make it to where it can only be modified by that function other than creating a private class within the class. I suppose that creating a private class is a good idea, but I would be interested if someone else has a different approach. AudioPlayer should never be allowed to change the volume without calling SetVolume. That's the code I have here, but I wondered

Overloading operator<< for a private enum

戏子无情 提交于 2019-12-11 10:28:05
问题 My class has a private enum whose members are being used to index an array of strings, the output of which is written to an output stream. private: enum supportedMessageTypes(CRITICAL = 0, WARNING, INFORMATION); string messages[3]; //meanwhile, inside the constructor, messages[3] = {"Critical error message", "Warning message", "Information message"}; Since I'm going to be using the enum values around my code a lot, I'd like to be able to overload operator<< to perform a lookup of the enum

Facebook api friends list

杀马特。学长 韩版系。学妹 提交于 2019-12-11 08:27:48
问题 I'm using Facebook's javascript SDK to inspect the friends list of users registered in my application. I have this call: FB.getLoginStatus(function (response) { if (response.status == 'connected') { FB.api('me/friends', { fields: 'id, first_name, picture', limit: 6 },function(response){ MY CODE TO VIEW FRIENDS PICTURE }); } else{ CODE TO GET ACCESS_TOKEN } }); but in most of cases I get an api error like this: response.error = { message: unkown error, code: undefined, type: http, subcode:

friend class/function in c++ [duplicate]

こ雲淡風輕ζ 提交于 2019-12-11 07:48:48
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: When should you use 'friend' in C++? I see a lot of people recommending a function/class to be made a friend of another class here in SO though there are other alternatives. Shouldn't friend be sparingly used in C++? I feel other options must be considered before deciding on using the friend feature. Opinions/suggestions are welcome. 回答1: Without specific examples this is hard to decide. While friend isn't

Protected “read only” proxy class for primitives in c++

会有一股神秘感。 提交于 2019-12-11 07:18:33
问题 I recently stumbled up this proxy class for making c++ primitive members "read only" (publicly act as const references, but privately non const). This potentially eliminates the need for boilerplate "getters". The proxy class looks like: template <Container,Primitive> class RO { friend Container; public: inline operator Primitive() const { return x; } template<typename Other> inline bool operator==(const Other& y) const { return x == y; } template<typename Other> inline bool operator!=(const

Does “friending” the base class in CRTP inheritance affect the child class as well?

僤鯓⒐⒋嵵緔 提交于 2019-12-11 04:49:47
问题 In an attempt to answer another question, I came up with a scheme to force children of a CRTP base class to accept a particular type as a parameter in their constructors: make the parameter type's constructor private , assign the CRTP base class as a friend , and declare the parameter type as a parameter for the base class constructor as well. However, when I tried to demonstrate that this scheme provided the desired protections via access violations, I found that even though the parameter

Can I manage incomplete class objects using STL containers?

谁说我不能喝 提交于 2019-12-11 04:17:00
问题 In C++11, it is definitely invalid to declare a vector of a class which is still an incomplete type right? I thought I could only use incomplete types as pointers, references, return types or parameter types. Searching (1) for "vector of incomplete type" suggests to me that containers of incomplete types should be an error (I'm using g++ version 4.8.1.). However the following code compiles fine on my system: #ifndef SCREEN #define SCREEN #include <string> using namespace std; class Screen;

Using friend function in C++

半城伤御伤魂 提交于 2019-12-11 03:46:42
问题 Just read about friend functions and I'm trying to access private variable "number" in class A with friend function "Print" from class B. I'm working with Visual Studio. Compilation of my code gives me plenty of various errors like: C2011: 'A' : 'class' type redefinition C2653: 'B' : is not a class or namespace name Please be patient with me me and show a proper way of achieving my goal. Here are my files A.h: class A { public: A(int a); friend void B::Print(A &obj); private: int number; }; A

Befriending a template class: Compile error

痞子三分冷 提交于 2019-12-11 03:39:15
问题 I'm trying to use the Pointer to Implementation Idiom to hide the fact that I am using a Concurrency::unbounded_buffer (from VC++ 2010). The problem is, I'm doing it with templates and got stuck in a compile error. Here's the code: BlockingQueue.h #pragma once namespace DRA{ namespace CommonCpp{ //Forward declaration template <class Element> class BlockingQueueImpl; template <class Element> class BlockingQueue{ BlockingQueueImpl<Element>* m_pImpl; //Forbid copy and assignment BlockingQueue(