Note that there are some explanatory texts on larger screens.

plurals
  1. POPointer initialization in constructors
    primarykey
    data
    text
    <p>I am developing a client-database using MFC and lately I was trying to create a class in order to perform DAO operations (instead of implementing these operations directly at the <code>CDocument</code> class). I named this class as <code>CModel</code>, and <code>CDocument</code> contains it. In order to perform SQL operations using the <code>CModel</code> class, I must have access to the <code>m_session</code> variable - which represents a database access session - and it can be found in the RecordSet class - which represent one table in a database of mine. Here is a piece of code to better illustrate the situation:</p> <pre><code>#pragma once #include "MFCApplicationSet.h" class CModel { public: CModel(CMFCApplicationSet ApplicationSet); ~CModel(); CMFCApplicationSet * pModelSet; } // Model.cpp : implementation file // #include "stdafx.h" #include "MFCApplication.h" #include "Model.h" #include "SQLQuery.h" #include "MFCApplicationSet.h" #ifdef _DEBUG #define new DEBUG_NEW #endif CModel::CModel(CMFCApplicationSet ApplicationSet) { pModelSet = &amp;ApplicationSet //not sure if it is right } CModel::~CModel() { } // MFCApplicationDoc.h : interface of the CMFCApplicationDoc class #pragma once #include "MFCApplicationSet.h" #include "Model.h" class CMFCApplicationDoc : public CDocument { protected: // create from serialization only CMFCApplicationDoc(); DECLARE_DYNCREATE(CMFCApplicationDoc) // Attributes public: CMFCApplicationSet m_MFCApplicationSet; CModel Model; } // MFCApplicationDoc.cpp : implementation of the CMFCApplicationDoc class // #include "stdafx.h" #ifndef SHARED_HANDLERS #include "MFCApplication.h" #endif #include "MFCApplicationSet.h" #include "MFCApplicationDoc.h" #include "Model.h" #ifdef _DEBUG #define new DEBUG_NEW #endif IMPLEMENT_DYNCREATE(CMFCApplicationDoc, CDocument) BEGIN_MESSAGE_MAP(CMFCApplicationDoc, CDocument) END_MESSAGE_MAP() // CMFCApplicationDoc construction/destruction CMFCApplicationDoc::CMFCApplicationDoc() { //problem in implementing a instruction to call the Model object constructor } CMFCApplicationDoc::~CMFCApplicationDoc() { } </code></pre> <p>I've used the debugger to analyse my code flow and I noticed that, from the <code>CMFCApplicationDoc</code> constructor (<code>CDocument</code>), the constructor from each variable declared in the <code>CMFCApplicationDoc.h</code> is initialized. Here's my problem: I've tried to create a <code>CModel</code> constructor in order to the <code>pModelSet</code> pointer automatically reference the variable <code>m_MFCApplicationSet</code> (check the constructor arguments) declared in the <code>Doc</code> class, but I am experiencing some trouble in giving this instruction inside the construction of the <code>Doc</code> class. Is there a specific or maybe an alternative way to do this? (sorry if this task is kind of elementary, but I am still very newbie in C++)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload