I was going through Singleton design pattern and get to know that objects can be created only by static function of that class and constructors are make private.
My question is, why assignment operators are not made private through which we can create a copy of already existing object.
I tried below code and assignment works, so I have new object sc3. I know that its referring to memory of sc1 but finally I was able to create object without using static function.
Also, why copy constructor not made as private.
Below is code:
#include <iostream> using namespace std; class Singleton { private: static bool instanceFlag;
#include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; class singleTon {
[Code] ....
this is a singleton pattern first,it doesn't matter, why I could delete this pointer twice?because the gcc compiler?That mean in the surface, "delete pInstance1;" this movement just mark the memory pInstance1 has been deleted but not real?does any one encounter this phenomenon?
is there any way to have the program control go some two paths at once? For example: if my program has two functions, one that does some simple calculation that requires nothing from outside it to set the variables and another that displays text for the user to read then enter something. Is there any way to have both run at the same time?
simpleFnc() {int a = 1; int b = 2 ; int c = a+b ;
[code]....
There is no connection of simplefnc to anywhere else in the program so is there any way to get it to run at the same time the other function is running?
I get a error "Not all code paths return a value" what is the reason i get this error
public String giveHint() { int hintPossible, x, y, val; _game.hint(out hintPossible, out x, out y, out val); if (hintPossible == 1) return "x: " + x + "y: " + y + "val: " + val; }
giveHint() has a red underline and it says not all code path returns a value ....
I need to design an interface(a function prototype) that takes an argument which is used to pass information. The information can be passed by independent modules and third party softwares and hence can vary today and in future.
Basically, the function interface(arg1, info)caters a niche service to many independent applications and needs to process based on requirements passed by applications in the argument(info, in example).
I am looking for a design pattern for the function parameter - info.
Should I use a void pointer that can be casted to respective application specific class in the function ? will this be a good C++ design ?
or should I take this parameter to be a pointer to a generic abstract class that points to the respective application specific specialization ?
Do we have some design pattern to address this so as to handle other unforeseen challenges ?
I need to design an interface(a function prototype) that takes an argument which is used to pass information.
The information can be passed by independent modules and third party softwares and hence can vary today and in future.
Basically, the function interface(arg1, info) caters a niche service to many independent applications and needs to process based on requirements passed by applications in the argument(info, in example).
I am looking for a design pattern for the function parameter - info.
Should I use a void pointer that can be casted to respective application specific class in the function ? will this be a good C++ design ?
or should I take this parameter to be a pointer to a generic abstract class that points to the respective application specific specialization ?
Do we have some design pattern to address this so as to handle other unforeseen challenges ?
In the following code example of the State Design Pattern, in the main code at the bottom it defines an instance of class Machine, and then calls Machine::off;. Why doesn't it instead call fsm.off;?
Machine fsm;
Machine::off;
Then I tried imitating that by adding a class Abba, and then doing:
Abba a; Abba::DoStuff();
but that didn't work. Why?
Full code example:
// StatePattern.cpp : Defines the entry point for the console application. //
#include "stdafx.h" #include <iostream> using namespace std; class Machine { class State *current;
I'm building a Windows Form Application using MVP Design Pattern; the application is quite simple, it just calculates the sum of two number; So I have a form in which are located tree textbox: number1 number2 and result, plus a button to perform the action.
I have written the below but I get an error when I run it. I get the below error.
$mcs main.cs -out:demo.exe 2>&1
main.cs(93,58): warning CS0162: Unreachable code detected main.cs(85,21): error CS0161: `CreditCards.CreditCardsValidator.LuhnCheckPerformed(string)': not all code paths return a value Compilation failed: 1 error(s), 1 warnings
The code is below: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; /**@return a Credit Card Validation Application
I am trying to read data from more than one file at once. The files are different types e.g. one is a text file one is an xml file like so, StudentInformation.txt, CollegeInformation.xml. The files are all stored in one place, in this case on the D drive of a local computer. I am trying to locate any files in the D drive with a file extension of .txt or of .xml (there may be more than two of these files in the future, so I'm trying to allow for that). Then I want to open all of these files, extract the information and output all the information in one display window. I want all the information from these two or more files to be displayed together in the display window.
Here is the code so far. It is throwing up errors.
I am trying out a technique for a singleton class:
// access controlled singleton, accessed through function "instance()" // singleton is constructed in this function // so that constructor and destructor will be used class single { // private constructor/destructor
[Code] .....
Playing around with the code in main(), I am having trouble with auto:
single& s = single::instance(); // works fine auto a = single::instance(); // error ~single() is private
When I make the destructor public, the output of the program is:
ctor dtor dtor
So I fixed this by typing auto&. I'm still confused though, why wouldn't auto know I am returning a reference?
I have a adjacency matrix. (router adjacency matrix in network). The result should be the router ID.I mean, print all the possible paths from source router to target router(ROUTER id>> 1 - 2 - 3 - 4 so there are four one router). I get the error in the output.)
Code: #include<stdio.h> #include<conio.h> /* graph: Pointer to the starting of mXn matrix i, j: Current position of the robot (For the first call use 0,0) m, n: Dimentions of given the matrix pi: Next index to be filed in path array
I have researched quite extensively, experimented, and still cannot seem to change the properties of a control on an active winform from a user control.
So I have a user control which populates each dynamically added tab page in a tab control.
I have a textbox in the user control which I would like to type in, capture the text_change event, and change the text of the label in the winform.
How do I bind a DATE column in a DataGridView Control to a DatePicker control (using C#)? I already have the DataGridView control bound to a database stored procedure which takes a DATE value as a parameter and selects joining table based on the results.
I'm trying to find vertical paths of length n through a 2D grid of numbers. Paths may connect orthogonally or diagonally. An example grid and an example possible path looks like this:
A example possible path of length n = 3 is running from (3,2) to (3,4) - All 1s ...An example of n = 4 is the run of 3s (1,1) (0,2) (0,3), (0,4)
What is an efficient algorithm for solving this kind of problem? I would like to solve (ideally) millions of grids, giving a list for each grid of all possible paths of length for n = 3-6.
I am trying to include library paths in VS 2012 through the new property pages.I downloaded and installed mpich2-64 bit libraries under "C:Program FilesMPICH2include" and set the include path in Microsoft.cpp.x64.user property file so the path now looks like
class BoundingBoxTest : public DemoApplication { public: #ifdef DYNAMIC_CHARACTER_CONTROLLER btCharacterControllerInterface* m_character;
[Code] ....
I am creating the object by calling : BoundingBoxTest::Create();
Do I make a getter to retrieve the demo object or do I build on the Create() method... So that it will return the instance if it is not null. and creates one if there is none?
I need to implement a singleton, so I've been reading about it online and I'm still not quite sure about all the types of constructors I need to declare:
I've tried to program a Singleton class. But the problem is that I don't know how to access the g_pInstance() function. Because this is not working because the constructor and deconstructor is private:
Singleton::g_pInstance() Code: #include <iostream> using namespace std; class Singleton {
[Code]....
I'm not sure of how to access any object, function, variables in the class when you are using a Singleton. How do you access that?
I'm just asking because I want to know how to do that if I have to use a Singleton sometime when I'm programming.
I have a class in my application that only needs to be created once, but the object needs to be available to all other classes in my application if necessary. Since declaring everything static can be restrictive (as I understand), I created a class like this:
class Foo { // Data members // Constructor/Destructor // Functions }; extern Foo* myFoo = new Foo();
And then the global variable gets deleted at the very end of the main method when everything is done:
#include "Foo.cpp" // (yes, I know this is normally bad, this is how I'm required to code) int main() { // do stuff delete myFoo; return 0; }
These won't link, though, because I get undefined reference linking errors to myFoo wherever I use it. I'm pretty sure this means I'm creating a singleton wrong, but I'm not sure what I'm doing wrong -- there's no const conflicts and the pointer is properly initialized (to my understanding). If there's a better way to do this than extern, I'm completely open to it, as long as it's understandable and works.