I was trying to derive a custom class from CMFCVisualManagerOffice2007. Can you suggest me steps to be followed in order to derive a CCustomMFCVisualManagerOffice2007?
I am getting following error:
error C2248:
'CMFCVisualManagerOffice2007::CMFCVisualManagerOffice2007': cannot
access protected member declared in class
'CMFCVisualManagerOffice2007'
I am looking for something on the lines of:
MFC CMFCVisualManager Override
Related
I have 4 classes, Customer, PickyCustomer, SegmentCustomer, and Delivery.
The Delivery class has a component within it called customer, like so:
class Delivery {
private:
Customer *customer;
Delivery(Customer *cust) // constructor
each of the Customer classes have a method called getAcceptable()
that is overrideable and is overridden within PickyCustomer and SegmentCustomer
From what I've read this is the correct way to call the overridden method from the Delivery class. By keeping the customer as a pointer it allows Delivery to call the child methods that override the base class.
But when trying to use unique_ptr I keep getting the error
no matching function for call to 'Delivery::Delivery(std::unique_ptr<Customer>*)'
when using the following bit of code to initialize
unique_ptr<Customer> cust1(new Customer("Name", "Home", 1000.0, 25.0, fileProduce));
shared_ptr<Delivery> cust1Delivery(new Delivery(cust1));
Can someone explain why I am getting this error, and show how I could fix this? Thanks.
Thanks to #paddy in the comments with the help! Using the get() function worked for me.
The below works for me.
unique_ptr<Delivery> cust1Delivery(new Delivery(cust1.get()));
I use touchGFX which is a C++ hmi for embedded devcices. I have the following problem and I am not sure how to solve it most effective. I need to access functions in the various StatusBar instances from MyModelListener (see below).
System description:
There is a model which holds the data, the views for the hmi and some presenters which interact between the model and the views. The base classes are automatically generated, I am allowed to modify all class with "My...". All My...Pesenters are linked with the corresponding My...Views by references in both directions.
I have some Presenters:
class MyAPresenter : public MyModelListener;
...
class MyZPresenter : public MyModelListener;
I have some Views belonging to the presenters:
class MyAView: public AViewBase;
...
class MyZView: public ZViewBase;
There is a status bar which should be used in each of the views:
class MyStatusbar : public Statusbar;
AViewBase, ..., ZViewBase each have a protected member instance of class MyStatusbar.
MyAPresenter, ..., MyZPresenter have a reference to MyAView, ..., MyZView.
How can I access (many) functions of MyStatusBar instances (inside the MyAView...) from MyModelListener without introducing as many functions into each MyAView... MyZView?
The data path how status bar can be reached is:
MyModelListener -> MyAPresenter -> MyAView -> AViewBase -> MyStatusbar
Problems:
I cannot access MyStatusbar instances from MyModelListener or MyAView via the AViewBase because MyStatusbar instances are declared protected within AViewBase.
I cannot modifiy AViewBase
I do not want to access MyStatusBar from MyAView..MyZView because I do not want to have all those many functions in each My...View.
I do not want to write all the needed functions in each of MyAPresenter...MyZPresenter.
(All the classes are virtual)
My solution:
Make functions getStatusPtr() returning the address of the Statusbar instances in each of MyAView to MyZView. This is possible because StatusBar is defined protected but not private.
Make virtual getStatusPtr() in each of MyAPresenter to MyZPresenter which calls the getStatusPtr() function in MyAView to MyZView via the owned references.
Define a virtual getStatusPtr() returning 0 in MyModelListener.
Access the StatusBar from MyModelListener if the pointer is not 0. This should deliver the the status bar of A if the MyModelListener functions are called from a MyAPresenter object.
If the View is changed both view and presenter are destroyed and the status bar too. The statusbar thus has to be rebuilt but this is acceptable.
Is there a better/alternative solution?
The MFC CMFCRibbonCheckBox class only supports IsChecked().
How do I change check status of ribbon check box in program code?
Is there way to set check status like CButton::SetCheck().
you can copy code from CMFCRibbonCmdUI::SetCheck. CMFCRibbonBaseElement::m_bIsPressed is a protected member so you need to expose it via a derived class. CMFCRibbonCmdUI has a backdoor to it through class friendship.
I try to implement a GType interface in C++ using Glibmm (part of Gtkmm). The object will be passed to an API in C. Unfortunately, the documentation for gtkmm does not cover many details of how it wraps the GObject system.
What I have so far:
class MonaCompletionProvider : public gtksourceview::SourceCompletionProvider, public Glib::Object
{
public:
MonaCompletionProvider();
virtual ~MonaCompletionProvider();
Glib::ustring get_name_vfunc() const;
// ... and some more
}
All method and constructor implementations are empty. The code is used like this:
Glib::RefPtr<MonaCompletionProvider> provider(new MonaCompletionProvider());
bool success = completion->add_provider(provider);
success will be false after executing this code and the following message appears in the command line:
(monagui:24831):
GtkSourceView-CRITICAL **:
gtk_source_completion_add_provider:
assertion
`GTK_IS_SOURCE_COMPLETION_PROVIDER
(provider)' failed
It seems that the underlying gobj() is not aware that it is supposed to implement this interface. If the class does not derive from Glib::Object, gobj() even returns null. I hope that I do not have to write a GObject implementing this interface in C manually.
So what is the correct way to do this? Thanks in advance.
PS: For those who are interested: SourceCompletionProvider
Finally, I found a solution.
Class definition (order of subclasses matters):
class MonaCompletionProvider : public Glib::Object, public gtksourceview::SourceCompletionProvider {
...
Constructor (again, order matters):
MonaCompletionProvider::MonaCompletionProvider() :
Glib::ObjectBase(typeid(MonaCompletionProvider)),
Glib::Object(),
gtksourceview::SourceCompletionProvider() {
...
Solution found by inspecting how it has been done in Guikachu.
I have a model class "Action" that get's extended by several other classes. I am new to django and assumed that if I called pre_save.connect(actionFunc, sender=Action) that actionFunc would get called anytime the save method in the Action class was called (including by any derived class).
My observation is that this function only gets triggered when the instance is a direct match of the Class type defined in Sender. Is there anyway to get this to recieve signals for all derived instances of Action as well?
No, you have to call the pre_save.connect as many number of times.
However, you can use python to get all the classes that extend the class of your interest, and loop over the pre_save connect statement.
Say, if the extended classes of the Action are all in a given file, you can do the following:
global_dict = globals().copy()
[el for el in global_dict.values() if getattr(el,'__base__',None)==Action]
one thing you can do is modify the signal sender in django so that instead of matching against a specific type it instead does
if isinstance(sender, filter):
send_signal()
(pseudocode)