How to implement the class Singleton cascading C++
I tried to use the standard C++ to implement the Singleton class. It can be compiled well, there's always a mistake to link "Description Resource path location Type cannot declare the member function ' static globalsettings * globalsettings::instance() ' static linking [-fpermissive] problem of C/C++.
Can anyone have a look of my source code to know what is the problem of it? Thank you.
/* * globalsettings.h */ #ifndef GLOBALSETTINGS_H_#define GLOBALSETTINGS_H_ class Globalsettings {public: Globalsettings(); virtual ~Globalsettings(); int get_value(); void set_value(int v); static Globalsettings &instance(); private: int m_value; static Globalsettings *s_instance;}; #endif
Wrong with the CPP:
/* * globalsettings.cpp * */ #include "globalsettings.h" Globalsettings* Globalsettings::s_instance = 0; Globalsettings::Globalsettings() { s_instance = 0; m_value = 0; } Globalsettings::~Globalsettings() { s_instance = 0; } static Globalsettings& Globalsettings::instance() { if (!s_instance) s_instance = new Globalsettings(); return *s_instance; } int Globalsettings::get_value() { return m_value; } void Globalsettings::set_value(int v) { m_value = v; }
CPP revised (it works)
/* * globalsettings.cpp * */ #include "globalsettings.h" Globalsettings* Globalsettings::s_instance = 0; Globalsettings::Globalsettings() { s_instance = 0; m_value = 0; } Globalsettings::~Globalsettings() { s_instance = 0; } Globalsettings& Globalsettings::instance() { if (!s_instance) s_instance = new Globalsettings(); return *s_instance; } int Globalsettings::get_value() { return m_value; } void Globalsettings::set_value(int v) { m_value = v; }
UPD:
1)
static globalsettings *s_instance;
This should be in the private section.
2)
static globalsettings *instance();
This should be public, so the user can call.
3)
Delete 'static' keyword to the .cpp file.
Even easier approach with late initialization:
all in 1):
static MyClass *sharedInstance();
(2) in the .cpp:
MyClass *MyClass::sharedInstance() { static MyClass instance; return &instance; }
Tags: BlackBerry Developers
Similar Questions
-
How to implement the ScreenUiEngineAttachedListener Interface?
How to implement the ScreenUiEngineAttachedListener Interface? It is somewhat a mystery reading through the API.
I have a class that implements ScreenUiEngineAttachedListener:
public class UiListener implements ScreenUiEngineAttachedListener { public void onScreenUiEngineAttached(Screen screen, boolean attached) { } }
Then I have a class MyScreen which extends from screen and has two methods:
public void addScreenUiEngineAttachedListener(ScreenUiEngineAttachedListener listener) { super.addScreenUiEngineAttachedListener(listener); } private void removeScreenUiEngineAttachedListener() { }
- What is the correct positioning of everything?
- Can I define an instance of UiListener and pass in the addScreenUiEngineAttachedListener?
- How to remove UiListener in removeScreenUiEngineAttachedListener?
You will need:
- an instance of your UiListener - probably a static member inside your UiApplication;
- a method that allows to retrieve the reference to this instance of UiListener;
- a call in your constructor for the screen at addScreenUiEngineAttachedListener (yourApplication.getUiListener ()) or similar;
- potentially a call within your onScreenUiEngineAttached (attached screen, boolean) routine, the branch (attachment is false) : screen.removeScreenUiEngineAttachedListener (this);
However, all this is too much work for no gain. Just override protected void onUiEngineAttached (boolean attached) in your screen class and make your logic there - all members of your class are accessible and all the code is placed where it belongs.
-
How to create several classes of cascade?
Goal: Create the button to start and stop the service.
Situation: One button works.
However, whenever I click on another button, the button does not work.
Question: how to create several classes of cascade?
or something wrong in my code?
Mini code:
Calls a CPP QML.
ApplicationUI::ApplicationUI (bb::cascades:Application * app): QObject (app)
{
QmlDocument * qml = QmlDocument::create("asset:///main.qml").parent(this);CameraWrapper * wrapper = new CameraWrapper();
QML-> setContextProperty ('wrapper', wrapper);
AbstractPane * root = qml->
() createRootObject;
App-> setScene (root);
}And then, QML calls another RPC.
import bb.cascades 1.0
{Page}
{Of container
layout: {DockLayout}
}
Button {}
text: qsTr ("Start")
onClicked: {}
wrapper.startRec ();
}
}
Button {}
text: qsTr ("Stop")
onClicked: {}
wrapper.stopRec ();
}
}
}
}The main CPP:
#include "cam.hpp".
using namespace bb::cascades;
{CameraWrapper::CameraWrapper()}
int CameraWrapper::startRec() {}
This button works.
}
int CameraWrapper::stopRec() {}
This button does not work.
}
The main.hpp
Class CameraWrapper: public QObject
{
Q_OBJECT
public:
CameraWrapper();
Virtual ~ CameraWrapper() {}Q_INVOKABLE
int startRec();
int stopRec();
};Thank you for your attention,
Finally, we use the thread to solve the problem.
Solution:
loopWrapper (void * test) {void *}
CameraWrapper * a = (CameraWrapper *) test;
a-> startRec();
return null;
}setFlagWrapper (void * test) {void *}
CameraWrapper * b = (CameraWrapper *) test;
b-> setFlagFalse)
return null;
}void * CameraWrapper::setFlagFalse (void * arg) {}
exit_application = false;
fprintf (stderr, "Flag changed to false\n");
return arg;
}void CameraWrapper::runLoop() {}
pthread_create (& thread_a, NULL, & loopWrapper, (void *) this);
}void CameraWrapper::runSetFlag() {}
pthread_create (& thread_b, NULL, & setFlagWrapper, (void *) this); -
How to implement the SOA 11 g limitation?
Hi all
Can someone tell me how to implement the limitation in SOA to create a repository for the history of the transactions?
ARO
Hari
Hello
By Greg Mally of Oracle message covers an approach to the limitation in SOA Suite
https://blogs.Oracle.com/soacommunity/entry/throttling_in_soa_suite_via
-
Is there anyone who knows how to implement the P3 Colorspace in first CC2014?
Is there anyone who knows how to implement the P3 Colorspace in first CC2014?
Hi RVBBernard,
Sorry, there is currently not available in Premiere Pro. You can request a feature here: http://adobe.ly/feature_request
Thank you
Kevin
-
How to implement the AdSense code
Hello
I don't know how to implement the code.
Can someone help me?
Hello
Please take a look on the link adobe form at the address below. This could help you.
https://forums.Adobe.com/message/4325647
Kind regards
Nitin Kapila
-
How to get the class Loader of Progress event
I was charge test.swf file threw Loader class. How to get the class Loader of ProgressEvent, IOErrorEvent.
function getLoader() {}
var loader: Loader = new Loader();
loader.contentLoaderInfo.addEventListener (ProgressEvent.PROGRESS, progressHandler)
loader.contentLoaderInfo.addEventListener (IOErrorEvent.IO_ERROR, ioErrorHandler);
var request: URLRequest = new URLRequest ("test.swf");
Loader.Load (request);
}
function progressHandler(event:ProgressEvent):void {}
get the class loader
}function ioErrorHandler(event:IOErrorEvent):void {}
get the class loader
}
getLoader()the event target has a property of charger:
Event.Target.Loader
-
How to implement the process Train in Jdev 10.1.3
Hello..
Anyone know where to find a tutorial on how to implement the process train in jdev 10.3.1
Thank youhttp://download-West.Oracle.com/docs/HTML/B25947_01/web_complex005.htm#CEGIGJID
-
How to implement the dependencies between the search criteria
Hi all
I use jdev11.1.1.6.
In one of my needs, I have to implement the dependencies between the criteria of research. I use two criteria serach and lov.
the second criteria lov should be listing all of the results based on the firstr search criteria.
I tried to use the dependencies options but no luck.
someone pls let me know how to implement this.
Thank you
SivaCheck this box:
http://mahmoudoracle.blogspot.com/2011/09/ADF-cascading-Lov.html#.UE3v3FHPeM8
http://dstas.blogspot.com/2009/02/dependent-lovs-in-query-criteria-and.html
http://adfpractice-Fedor.blogspot.com/2012/06/dependent-lov-in-search-form.html -
How XAI implements the 'do more' function in CC &; B pages
Hi all
There is a button "get more" in CC & B page if you put more than 50 recordings, just by clicking on the button when I want to get the latest recordings, but how do I implement the same function by XAI, I studied a lot of time on this problem and got nothing. so, everyone here had encounterd the same question? and resolved?
any help would be appreciated.The GET more feature works in the browser because there is a separate servlet 'list' that retrievs data. It is based on some data to the HTTP context for correct operation. Unfortunately the 'do more' function is not supported by the Servlet XAI (it does not on the context HTTP data). Your only option is to roll your own mechnaism of paging for the data that you need.
The model is going to like it...
1. develop SQL code for what you want to paginate
2. create a new "Listings Service" class that acts as a underlying service
3 mark the service with entries include the size of the page and you want to retrieve the page number
4. annotate the service with a list of data that will be returned
5. use the page size and page number to create and run the query, and build the result
6 enter the service as a Service of inbound XAI
7. deploy the code
8. test using dynamic presentationfor example. Here is one more example for the search values...
import com.splwg.base.api.BusinessEntity;
import com.splwg.base.api.SimpleEntityList;
import com.splwg.base.api.service.DataElement;
import com.splwg.base.api.service.ItemList;
import com.splwg.base.api.service.ListBody;
import com.splwg.base.domain.common.lookup.LookupField_Id;
import com.splwg.base.domain.common.lookup.LookupValue;
import com.splwg.base.domain.common.lookup.LookupValue_Id;
import com.splwg.base.support.service.metainfo.ListBodyField;
import com.splwg.shared.environ.ServiceListConstant;
import com.splwg.shared.logging.Logger;
import com.splwg.shared.logging.LoggerFactory;/**
*
* @author edhoi
@ListService (name = CmGetMoreListValues, size = 10000, = CMLGETMRL, CMLGETMRL = service program,
* body = @DataElement (content = {@DataField (name = METER))
({*, @RowField (entity = ValRech, name = ValRech)});
* headerFields = {@DataField (name = ELEM_SIZE)
*, @DataField (name = FIELD_NAME)
({*, @DataField (name = FIELD_VALUE)})
*/
SerializableAttribute public class CmGetMoreListMaintenance extends CmGetMoreListMaintenance_Gen {}public private static final logger LOG = LoggerFactory.getLogger (CmGetMoreListMaintenance.class);
@Override
protected{readList()} ItemList Call CmGetMoreBusinessComponent
CmGetMoreBusinessComponent cmGetMoreBusinessComponent = CmGetMoreBusinessComponent.Factory
. newInstance();
LookupField_Id lookupField_Id = new LookupField_Id (getHeader () .get)
CmGetMoreListMaintenance.STRUCTURE.HEADER.FIELD_NAME));
LookupValue_Id lookupValueId = new LookupValue_Id (lookupField_Id,
getHeader () .get)
CmGetMoreListMaintenance.STRUCTURE.HEADER.FIELD_VALUE));
BigInteger pageSize = getHeader () .get)
CmGetMoreListMaintenance.STRUCTURE.HEADER.ELEM_SIZE);
ValRech lastValue = lookupValueId.getEntity ();The list of values
= cmGetMoreBusinessComponent
.getLookupValuePageData (lookupField_Id, lastValue, pageSize
(. intValue());long count = cmGetMoreBusinessComponent
.countLookupValues (lookupField_Id);If (values.size () > 0) {}
lastValue = values.get (values.size () - 1);
} else {}
lastValue = null;
}
ItemListitemList = new ItemList (CmGetMoreListMaintenance.STRUCTURE.list_CmGetMoreListValues.name);
ListBody listBody = itemList.newListBody ();
listBody.put (CmGetMoreListMaintenance.STRUCTURE.list_CmGetMoreListValues.COUNTER, (BigInteger) new
Long.toString (count)));
If (lastValue! = null) {}
listBody.put (CmGetMoreListMaintenance.STRUCTURE.list_CmGetMoreListValues.FIELD_VALUE, lastValue.getId () .getFieldValue ());
}
for (ValRech value: values) {}
Data listElement = itemList.newDataElement ();
listElement.addRow (value.getDTO ());
}
return itemList;
}
@Override
protected void afterPopulateList_CmGetMoreListValues)
ItemListtargetList, SimpleEntityList sourceList,
BusinessEntity sourceListParent) {}
TODO self-generating method stub
super.afterPopulateList_CmGetMoreListValues (targetList, sourceList,
sourceListParent);
}
} -
How to implement the reading of data from a matte file on a cRIO?
Hi all!
I'm still not sure, it is plausible, but I'll ask rather before you begin complicating. So far, I found no useful information on reading in the data to a device of RT from a file (type of a simulation test - data is simulated).
I have the MatLab plugin that allows the storage of data read a MAT file, which has a number of columns that represent the different signals and lines representing the samples at a time (depending on the time of the sample - sample every time has its own line of signal data).
I have no idea how to implement this at cRIO.
The idea is:
I have some algorithms running on the controller of RIO in a timed loop. As the entries of these algorithms I need to access each of the values of columns in the row, which is the time of the sample (sort of a time series - without written actual times).
I am fairly new to RT and LV development, so any help would be appreciated.
Thank you
Luka
Dear Luka!
I think the reading of all the samples in a single channel is exactly what you need here, because reading the files may take some time and is not deterministic, so it is best to read all the data in memory (or if this is not feasible due to problems of size, fairly large pieces may be sufficient). The table read can be provided and then in the loop simulating outings, something like this:
I used here separate channels so it's more graphic, but you can build all the channels in a 2D array and array index corresponding to the samples fom 1 who. You can also use for loops with indexing as tunnels are setup and then you won't need the index functions and the number of iterations is also set automatically, but you have to take care of synchronization settings.
Best regards:
Andrew Valko
National Instruments
-
How to implement the wafer map using LabVIEW?
Hello LabVIEW Masters!
I have a project which includes control and searching for information on a PROBER. One of the difficulties I have now is how to implement a WAFER card using LabVIEW. According to the requirements of my client, the element of pads varies between 6 k and 23 k. I guess that do everything (a = a ctl/indicator led) will be a hell of a task, especially on how to effectively manipulate each elements. Does anyone have a better idea on the way whose that?
Please, I seriously need your help...
Thank you and best regards,
Dennis DG
Hi Dennis,
This wafer GerdW post card appears to me as a sort of histogram (for example http://www.ni.com/white-paper/4158/en#toc3);
Altenbach post well this example that shows how to use a plot of intensity to create a 2d histogram:
http://forums.NI.com/T5/LabVIEW/overlay-plots-as-intensity-graph/m-p/211222#M119248
Learn how it works and try to adapt it to your specific task.
Alex
-
How to connect the slot button Cascades
I am new to waterfalls and QML and yesterday I tried to port native QtWidget app to waterfalls, but it does not. The problem is, I add some buttons to the container in QML main file and coded my custom slot function which should be executed when the user click some button. But I don't know how to connect the clicked() signal to my function from the custom location.
When using
Connect (CloseButton, signal(Button::clicked()),this,slot(on_closeButton_clicked()));) or connect (exitButton, SIGNAL (clicked ()), this, SLOT (on_exitButton_clicked ())); I get error "unable to connect SIGNAL (null) to SLOT (on_closeButton_clicked ()) ' on all the buttons.
Here is my code in app.cpp
App::App() { QmlDocument *qml = QmlDocument::create("main.qml"); qml->setContextProperty("cs", this); AbstractPane *root = qml->createRootNode
(); Application::setScene(root); textHolder = root->findChild And qml
import bb.cascades 1.0 Page { id: mainPage content: Container { id: main Container { id: buttonHolder scrollMode: ScrollMode.None layout: StackLayout { layoutDirection: LayoutDirection.LeftToRight leftPadding: 5.0 rightPadding: 5.0 topPadding: 5.0 bottomPadding: 5.0 } touchPropagationMode: TouchPropagationMode.None objectName: "buttonHolder" Button { id: openButton text: "Open" } Button { id: closeButton text: "Close" onClicked: { } } Button { id: saveButton text: "Save" onClicked: { } } Button { id: saveAsButton text: "Save As" onClicked: { } } Button { id: exitButton text: "Exit" } } //******************************** Container { id: textHolderArea layout: AbsoluteLayout { } topMargin: 5.0 leftMargin: 1.0 rightMargin: 1.0 bottomMargin: 2.0 TextArea { id: textHolder textStyle.fontStyleHint: FontStyleHint.Default layoutProperties: AbsoluteLayoutProperties { } leftMargin: 5.0 rightMargin: 5.0 preferredHeight: 645.0 textStyle.justification: TextJustification.Enabled objectName: "textHolder" text: "" } } //******************************** } }
And I have no idea how call my app.cpp C++ slot in my main QML file
Your buttons should an objectName set to be visible to C++, the id is only visible inside the QML.
-
How to implement the management of the application users?
I need to know how to add the possibility of application to create, modify, or delete user by user accounts manager [I count special wolud create in application]? I want to create the solution that includes 5 departments and each Department has few users. If the user is in Group would be pages prepared for the Group's engineers, tabset if user is in Group accountants would be a tabset prepared for accountants, etc. etc. Ability to create, modify, or delete user accounts must be implemented for manager who should be able to move users between groups if necessary.
Duplicate thread: Manage users in the application
Please close this message and continue the original discussion.
-
How to implement the logic below?
Hi friends,
Greeting of the day!
I have a table with the following columns
STUDY_NAME
COUNTRY
STUDY_SITE
DISCREPANCY_ID
REVIEW_STATUS
COMMENT_TEXT
I would like to implement the following logic on the table of the table
logic: I need to extract all the columns in the table above with the following condition,.
If the COMMENT_TEXT begins with 'CCRA Query' or 'ARC Central' and the REVIEW_STATUS is Review_Status 'ARC Review' = 'CCRA Review' if Review_Status = Review_Status.
Thanks in advance
Please give entered how implement the foregoingUse CASES
case when ( COMMENT_TEXT like 'cCRA Query%' or COMMENT_TEXT like 'Central CRA%' ) and REVIEW_STATUS = 'CRA Review' then 'cCRA Review' else Review_Status end as Review_Status
Maybe you are looking for
-
Can I use an SD card with the new MacBook?
Looking to buy a new MacBook. From what I can tell there is no SD card reader. I don't see any accessory adapter for SD readers either. Is it possible to use an SD card with the new MacBook? Thank you!
-
could you change the behavior of ff in full screen? I hate it when I move the whole page view tab bar. tab bar should slide on the page without moving
-
HP envy m6: broken hinge hp envy m6
Hello I complained on this subject more than a week ago here http://h30434.www3.HP.com/T5/HP-Cafe-and-Lounge/HP-envy-M6-broken-hinge-issue/m-p/5095968 Jeff asked me to send my information which I did but I've never heard of someone at hp Could you gu
-
MacOS 10.9 scanner and CM1415fnw won't save what it shows also scanned.
I have a CM1415fnw all-in-one and was scanning in grayscale controls at 200 dpi and saving to jpg fine under MacOS 10.8. I upgraded to 10.9 MacOS and the update of Applel because it has been installed. Now when I'm scanning a check or any document
-
Fault of updated for Powerpoint 2007
I have a question where Windows update guard trying to install an update for Powerpoint 2007 and failing. It is a failure because the app no longer exists. I think it was just bad timing that the update came through right all the time, that the app h