I am trying to add a command-line interface to an existing MFC application, and found a class online at this website. I have adapted it to my needs and when I try to build I get an error that reads "error C2248: 'CCustomCommandLineInfo::CCustomCommandLineInfo' : cannot access private member declared in class 'CCustomCommandLineInfo'" here's my code:
class CCustomCommandLineInfo : public CCommandLineInfo
{
CCustomCommandLineInfo()
{
//m_bExport = m_bOpen = m_bWhatever = FALSE;
m_bNoGUI = m_baMode = FALSE;
}
// for convenience maintain 3 variables to indicate the param passed.
BOOL m_bNoGUI; //for /nogui (No GUI; Command-line)
BOOL m_baMode; //for /adv (Advanced Mode)
// BOOL m_bWhatever; //for /whatever (3rd switch - for later date)
//public methods for checking these.
public:
BOOL NoGUI() { return m_bNoGUI; };
BOOL aModeCmd() { return m_baMode; };
//BOOL IsWhatever() { return m_bWhatever; };
virtual void ParseParam(const char* pszParam, BOOL bFlag, BOOL bLast)
{
if(0 == strcmp(pszParam, "/nogui"))
{
m_bNoGUI = TRUE;
}
else if(0 == strcmp(pszParam, "/adv"))
{
m_baMode = TRUE;
}
// else if(0 == strcmp(pszParam, "/whatever"))
// {
// m_bWhatever = TRUE;
// }
}
};
And here's what I have in my InitInstance()
// parse command line (cmdline.h)
CCustomCommandLineInfo oInfo;
ParseCommandLine(oInfo);
if(oInfo.NoGUI())
{
// Do something
}
else if(oInfo.aModeCmd())
{
// Do whatever
}
How would I go about fixing this?
You have:
class CCustomCommandLineInfo : public CCommandLineInfo
{
CCustomCommandLineInfo()
{
//m_bExport = m_bOpen = m_bWhatever = FALSE;
m_bNoGUI = m_baMode = FALSE;
}
That makes the default constructor a private function. That's why you can't use:
CCustomCommandLineInfo oInfo;
Make the default constructor public.
class CCustomCommandLineInfo : public CCommandLineInfo
{
public:
CCustomCommandLineInfo()
{
//m_bExport = m_bOpen = m_bWhatever = FALSE;
m_bNoGUI = m_baMode = FALSE;
}
Related
Well i made a bunny that teleports on tap and i want to make it so if you hold for more than 0.3f a bubble activates and protects it i tried multiple code variates but i cant get it to work in some situation the bunny teleports and activates the bubble after and in others it doesnt i know its something simple and i just have to adjust the if / else if so i will be thankfull for eny help
using UnityEngine;
using System.Collections;
public class tap : MonoBehaviour {
// Use this for initialization
public GameObject Bunny;
public GameObject BunnyUpEffect;
public GameObject BunnyDownEffect;
public static bool IsHeld = false;
float TimeHeld = 0f;
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton (0)) {
TimeHeld += Time.deltaTime;
if (TimeHeld > 0.3f) {
BubbleScript.BubbleActive = true;
IsHeld = true;
}
}
else {
BubbleScript.BubbleActive = false;
IsHeld = false;
TimeHeld = 0f;
if (Input.GetMouseButtonDown(0) && IsHeld == false) {
if (BunnyScript.BunnyAlive == true) {
if (BunnyScript.RunBottom == true) {
if (Stats.Energy > 0) {
BunnyUpEffect.GetComponent<BunnyUpEffect> ().Up ();
}
} else if (BunnyScript.RunBottom == false) {
BunnyDownEffect.GetComponent<BunnyDownEffect> ().Down ();
}
Bunny.GetComponent<BunnyScript> ().ChangePos ();
}
}
}
}
}
I want to get all property in child class and all from base class when i add it into List<>.
My Child class "SellNumber.cs":
class SellNumber : Entity
{
public SellNumber()
{
TableName = "tbl_sell_number";
Record_status = (int)EStatusRecord.NEW;
Buyer_number = new SecurityHelper().getCurrentIndexOfBuyer();
}
private long id_number;
public long Id_number
{
get { return id_number; }
set { id_number = value; }
}
private int lottery_buy;
public int Lottery_buy
{
get { return lottery_buy; }
set { lottery_buy = value; }
}
private long price_buy_number;
public long Price_buy_number
{
get { return price_buy_number; }
set { price_buy_number = value; }
}
private long buyer_number;
public long Buyer_number
{
get { return buyer_number; }
set { buyer_number = value; }
}
private int channel_id;
public int Channel_id
{
get { return channel_id; }
set { channel_id = value; }
}
private int shift_id;
public int Shift_id
{
get { return shift_id; }
set { shift_id = value; }
}
}
Base class
class Entity : BaseEntity
{
public Entity()
{
User_create = new SecurityHelper().getCurrentUser();
User_update = new SecurityHelper().getCurrentUser();
Date_create = DateHelper.DATE_TO_DAY_DAYTIME;
Date_update = DateHelper.DATE_TO_DAY_DAYTIME;
}
private long user_create;
public long User_create
{
get { return user_create; }
set { user_create =value; }
}
private long user_update;
public long User_update
{
get { return user_update; }
set { user_update = value; }
}
private String date_create;
public String Date_create
{
get { return date_create; }
set { date_create = value; }
}
private String date_update;
public String Date_update
{
get { return date_update; }
set { date_update = value; }
}
private int record_status;
public int Record_status
{
get { return record_status; }
set { record_status = value; }
}
}
Edited:
I want to get all property in child class and all from base class when i add it into List<>. I have class 'SellNumber.cs' which extends from class 'Entity.cs', so I want to use all properties of parent class to use with collection 'List'.
What is a good way to make a polymorph Task interface?
I want to design an interface for a processing library, which takes different data objects.
All data objects inherit from a IDataObject class.
The objects should be passed to the task throug a setInput(IDataObject* input) function.
I want to be able to define which kind of data object is needed. Maybe through a function setRequieredInput(DataObjectBase* input).
It should be possible to find Tasks which are able to process a data object maybe like this vector<Task*> getTasks(DataObjectBase* input). Like a Microkernel (Dependency Container)?
All suggestions are welcome.
I listed an first shoot below:
class IDataObject {
// Visitor style implementation
virtual void multiDispatch(Task* task) = 0;
}
class ISingleAccessDataObject : IDataObject {
// Visitor style implementation
// would this work orcan't I use the definition derived
// virtual function for the "interface" and class?
// If I'm right this is the diamond problem (inheriting the same
// function twice).
virtual void multiDispatch(Task* task) = 0;
double getData(int i) = 0;
}
class DataObjectBase : IDataObject {
// Visitor style implementation
virtual void multiDispatch(Task* task) {
task->execute(this);
}
// ...
}
class DataObjectBase {
// Visitor style implementation
virtual void multiDispatch(Task* task) {
task->execute(this);
}
// ...
}
class DerivedDataObject : DataObjectBase, ISingleAccessDataObject {
// Visitor style style Implementation
virtual void multiDispatch(Task* task) {
task->execute(this);
}
// ...
}
class Task {
void setInput(DataObjectBase* input) {
if (checkCanHandle(input) {
m_inputs.push_back(input);
}
}
void execute() {
for (int i = 0; i < m_Inputs.size(); i++) {
IDataObject* dataObject = m_Inputs.at(i);
if (dataObject == NULL) {
continue;
}
//-----------------------
// Visitor style implementation
dataObject.multiDispatch(this);
//-----------------------
// or
//-----------------------
if (Derived1DataObject* derived1DataObject = dynamic_cast<Derived1DataObject>(dataObject )) {
// ...
} else if (ISingleAccessDataObject* singleAccessDataObject = dynamic_cast<SingleAccessDataObject>(dataObject)) {
// ...
} else { //Log error }
//-----------------------
}
}
// Visitor style implementation
//-----------------------
// This would require to know all DataObjects on defining the
// Task "Interface". What is not really what I want.
void execute(Derived1DataObject* input) {
// ..
}
void execute(Derived2DataObject* input) {
// ..
}
void execute(ISingleIndexAccessDataObject* input) {
// ..
}
//-----------------------
bool checkCanHandle(DataObjectBase* input) {
for (int i = 0; i < m_HandleDataObjects.size(); i++) {
// Question: Is there a way to let this be true if
// m_HandleDataObjects.at(i) is a super class of input?
// Question: Is there a way to allow only save something like
// the typeid. Maybe name, but I'm not sure if name is the best
// option.
if (typeid(m_HandleDataObjects.at(i)) == typeid(input)) {
return true;
}
}
}
vector<DataObjectBase*> m_HandleDataObjects;
vector<DataObjectBase*> m_Inputs;
}
class TaskRegister {
vector<Task*> getTasks(IDataObject* input) {
vector<Task*> ret;
for (int i = 0; i < m_Tasks.size(); i++) {
// Question: Is there a better way using a HashMap or something else
if (m_Tasks.at(i).checkCanHandle(input)) {
ret.push_back(m_Tasks.at(i));
}
}
return ret;
}
vector<Task*> m_Tasks;
}
I am trying to call a function which is located in the program from a DLL.
The program is closed source but the structures are know.
I need to call a function called "GetPlayerPosition" which looks like this:
// native GetPlayerPos(playerid, &Float:x, &Float:y, &Float:z)
static cell AMX_NATIVE_CALL n_GetPlayerPos(AMX *amx, cell *params)
{
CHECK_PARAMS(4);
CPlayer* pPlayer = pNetGame->GetPlayerPool()->GetAt((BYTE)params[1]);
if (pPlayer)
{
cell* cptr;
amx_GetAddr(amx, params[2], &cptr);
*cptr = amx_ftoc(pPlayer->m_vecPos.X);
amx_GetAddr(amx, params[3], &cptr);
*cptr = amx_ftoc(pPlayer->m_vecPos.Y);
amx_GetAddr(amx, params[4], &cptr);
*cptr = amx_ftoc(pPlayer->m_vecPos.Z);
return 1;
} else {
return 0;
}
}
I want to call this part from my DLL/SO:
pNetGame->GetPlayerPool()->GetAt((BYTE)<my own input data here>);
I know the streucture/classes are this:
typedef struct _VECTOR {
float X,Y,Z;
} VECTOR, *PVECTOR;
CNetGame *pNetGame = NULL;
class CNetGame
{
private:
CPlayerPool *m_pPlayerPool;
public:
CNetGame();
~CNetGame();
CPlayerPool * GetPlayerPool() { return m_pPlayerPool; };
};
void CNetGame::Init(BOOL bFirst = false)
{
// Setup player pool
if(!m_pPlayerPool) {
m_pPlayerPool = new CPlayerPool();
} else {
m_pPlayerPool->ResetPlayerScoresAndMoney();
}
}
class CPlayerPool
{
private:
BOOL m_bPlayerSlotState[MAX_PLAYERS];
CPlayer *m_pPlayers[MAX_PLAYERS];
public:
CPlayerPool();
~CPlayerPool();
BOOL New(BYTE bytePlayerID, PCHAR szPlayerName);
BOOL Delete(BYTE bytePlayerID, BYTE byteReason);
// Retrieve a player
CPlayer* GetAt(BYTE bytePlayerID) {
if (bytePlayerID >= MAX_PLAYERS) { return NULL; }
return m_pPlayers[bytePlayerID];
};
};
class CPlayer
{
private:
BYTE m_bytePlayerID;
public:
CPlayer();
~CPlayer() {};
VECTOR m_vecPos;
};
So how would I call pNetGame->GetPlayerPool()->GetAt((BYTE)<my own input data here>); with this setup?
I just create an object of a class. One of the properties of this class is a List of objcet of another class. when I want to cast an object from the second class in this list this error "Object reference not set to an instance of an object" will be given.
This is the code for the first class:
public class RCSection<Bar>
{
private string RCSectionName;
private int NumberOfBars;
private double NumberOfInnerBars;
private double NumberOfOuterBars;
private double TransverseSpacing;
private Steel LongitudinalSteel;
private Steel TransevrseSteel;
private Concrete Concrete;
private List<Bar> LongitudinalBar;
private Bar TransverseBar;
private Section Section;
public string rCSectionName
{
set { RCSectionName = value; }
get { return RCSectionName; }
}
public int numberOfBars
{
set { NumberOfBars = value; }
get { return NumberOfBars; }
}
public double transverseSpacing
{
set { TransverseSpacing = value; }
get { return TransverseSpacing; }
}
public double numberOfInnerBars
{
set { NumberOfInnerBars = value; }
get { return NumberOfInnerBars; }
}
public double numberOfOuterBars
{
set { NumberOfOuterBars = value; }
get { return NumberOfOuterBars; }
}
public Steel longitudinalSteel
{
set { LongitudinalSteel = value; }
get { return LongitudinalSteel; }
}
public Steel transverseSteel
{
set { TransevrseSteel = value; }
get { return TransevrseSteel; }
}
public Concrete concrete
{
set { Concrete = value; }
get { return Concrete; }
}
public List<Bar> longitudinalBar
{
set { LongitudinalBar = value; }
get { return LongitudinalBar; }
}
public Bar transverseBar
{
set { TransverseBar = value; }
get { return TransverseBar; }
}
public Section section
{
set { Section = value; }
get { return Section; }
}
}
At first I wanna know, the way that I create a property for a list, is it right?!
after that, the following code is related to use of object of this class and casting an object in it
for (int i = 0; i < myRCSection.numberOfBars; i++)
{
Bar mybar = new Bar(newFormRCSection.comboBoxSteelSize1.Text,"SI");
myRCSection.longitudinalBar[i] = mybar;//Error will appear here :(
}
I found the answer. when I defined the new object of RCSection I should define the List related to this object
RCSection myRCSection= new RCSection<Bar>();
myRCSection.longitudinalBar = new List<Bar>();