Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Call a function from another class

Call a function from another class

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paulraj G
    wrote on last edited by
    #1

    I have 2 classes. Class A:

    void CDbModReactor::objectModified(const AcDbDatabase* pDb,
    const AcDbObject* pDbObj)
    {
    AcAxDocLock docLock(pDbObj->ownerId(), AcAxDocLock::kNormal);

    if(docLock.lockStatus() != Acad::eOk)
    	return;
        else
    	gpDlg->OnCopy2Excell("modified", pDbObj);
    

    }

    Class B:

    void CSampDialog::function1()
    {

    FILE \* pFile;
    	pFile = fopen ("C:myfile.csv","a");
    	if (pFile!=NULL)
    	{
    
    	CString x2 = Cent\_X+","+Cent\_Y+"\\n";
    	fwrite(x2, x2.GetLength(), 1, pFile);
    	fclose (pFile);
    	}
    

    }

    Now i have to call the function void CDbModReactor::objectModified(const AcDbDatabase* pDb, const AcDbObject* pDbObj) from void CSampDialog::function1() How can i call... Please help me...

    G.Paulraj

    L N 2 Replies Last reply
    0
    • P Paulraj G

      I have 2 classes. Class A:

      void CDbModReactor::objectModified(const AcDbDatabase* pDb,
      const AcDbObject* pDbObj)
      {
      AcAxDocLock docLock(pDbObj->ownerId(), AcAxDocLock::kNormal);

      if(docLock.lockStatus() != Acad::eOk)
      	return;
          else
      	gpDlg->OnCopy2Excell("modified", pDbObj);
      

      }

      Class B:

      void CSampDialog::function1()
      {

      FILE \* pFile;
      	pFile = fopen ("C:myfile.csv","a");
      	if (pFile!=NULL)
      	{
      
      	CString x2 = Cent\_X+","+Cent\_Y+"\\n";
      	fwrite(x2, x2.GetLength(), 1, pFile);
      	fclose (pFile);
      	}
      

      }

      Now i have to call the function void CDbModReactor::objectModified(const AcDbDatabase* pDb, const AcDbObject* pDbObj) from void CSampDialog::function1() How can i call... Please help me...

      G.Paulraj

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Paulraj G wrote:

      How can i call..

      Create an instance of the CDbModReactor class and call the function as required. This is basic C++, and if you do not understand how to do it you may need to go back to your learning materials.

      P 1 Reply Last reply
      0
      • L Lost User

        Paulraj G wrote:

        How can i call..

        Create an instance of the CDbModReactor class and call the function as required. This is basic C++, and if you do not understand how to do it you may need to go back to your learning materials.

        P Offline
        P Offline
        Paulraj G
        wrote on last edited by
        #3

        Hi... Thanks for your reply. This is the basic thing that i know. but i don't have variable to pass from here. if i call the function like

        CDbModReactor cdbmod;
        cdbmod.objectModified();

        that shows error. also i have tried like

        CDbModReactor cdbmod;
        cdbmod.objectModified(pDb, pDbObj);

        i don't have variables. that is the problem. with out variables how can i call the function?

        G.Paulraj

        L W 2 Replies Last reply
        0
        • P Paulraj G

          Hi... Thanks for your reply. This is the basic thing that i know. but i don't have variable to pass from here. if i call the function like

          CDbModReactor cdbmod;
          cdbmod.objectModified();

          that shows error. also i have tried like

          CDbModReactor cdbmod;
          cdbmod.objectModified(pDb, pDbObj);

          i don't have variables. that is the problem. with out variables how can i call the function?

          G.Paulraj

          W Offline
          W Offline
          WoutL
          wrote on last edited by
          #4

          You cannot call the function without variables.

          Wout Louwers

          P 1 Reply Last reply
          0
          • P Paulraj G

            Hi... Thanks for your reply. This is the basic thing that i know. but i don't have variable to pass from here. if i call the function like

            CDbModReactor cdbmod;
            cdbmod.objectModified();

            that shows error. also i have tried like

            CDbModReactor cdbmod;
            cdbmod.objectModified(pDb, pDbObj);

            i don't have variables. that is the problem. with out variables how can i call the function?

            G.Paulraj

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Like I said before, I think you need to go back to learning the basics of classes and objects. Your call to cdbmod.objectModified() needs to pass the parameters required by that method.

            1 Reply Last reply
            0
            • W WoutL

              You cannot call the function without variables.

              Wout Louwers

              P Offline
              P Offline
              Paulraj G
              wrote on last edited by
              #6

              ok...

              G.Paulraj

              1 Reply Last reply
              0
              • P Paulraj G

                I have 2 classes. Class A:

                void CDbModReactor::objectModified(const AcDbDatabase* pDb,
                const AcDbObject* pDbObj)
                {
                AcAxDocLock docLock(pDbObj->ownerId(), AcAxDocLock::kNormal);

                if(docLock.lockStatus() != Acad::eOk)
                	return;
                    else
                	gpDlg->OnCopy2Excell("modified", pDbObj);
                

                }

                Class B:

                void CSampDialog::function1()
                {

                FILE \* pFile;
                	pFile = fopen ("C:myfile.csv","a");
                	if (pFile!=NULL)
                	{
                
                	CString x2 = Cent\_X+","+Cent\_Y+"\\n";
                	fwrite(x2, x2.GetLength(), 1, pFile);
                	fclose (pFile);
                	}
                

                }

                Now i have to call the function void CDbModReactor::objectModified(const AcDbDatabase* pDb, const AcDbObject* pDbObj) from void CSampDialog::function1() How can i call... Please help me...

                G.Paulraj

                N Offline
                N Offline
                Nelek
                wrote on last edited by
                #7

                In your own code...

                gpDlg->OnCopy2Excell("modified", pDbObj);

                That seems to me as a external call from your class "CDBModReactor" to the class pointed by "gpDlg" containing the function "OnCopy2Excell", so... if this is like that... you have answered your question by yourself. (Supposing you have written the code)

                Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups