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. Class not visible

Class not visible

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpquestioncareer
16 Posts 7 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.
  • B Offline
    B Offline
    billiam904
    wrote on last edited by
    #1

    I am a newbie to vc++. I did some C 15 years ago... but, normally, I'm a vb.net guy. However, my current job is VC++ and my boss wants me to place a class inside a .h and .cpp file that already has an existing class. I did this fine but when trying to define an instance of this class from another class, it seems invisible even though I have included the .h file. Here's my code: file1.h class Class1 { // definitions here }; class Class2 { // definitions here }; File1.cpp: #include "file1.h" Class1::SomeFunction() { } Class2::AnotherFunction() { } File 2.h #include "File1.h" class Class3 { Class2 cClass2; // not visible. }; Any ideas? Bill Dennis Orlando, FL

    C D 2 Replies Last reply
    0
    • B billiam904

      I am a newbie to vc++. I did some C 15 years ago... but, normally, I'm a vb.net guy. However, my current job is VC++ and my boss wants me to place a class inside a .h and .cpp file that already has an existing class. I did this fine but when trying to define an instance of this class from another class, it seems invisible even though I have included the .h file. Here's my code: file1.h class Class1 { // definitions here }; class Class2 { // definitions here }; File1.cpp: #include "file1.h" Class1::SomeFunction() { } Class2::AnotherFunction() { } File 2.h #include "File1.h" class Class3 { Class2 cClass2; // not visible. }; Any ideas? Bill Dennis Orlando, FL

      C Offline
      C Offline
      Colonel Walter E Kurtz
      wrote on last edited by
      #2

      Are you using namespaces in file1.h ? What extactly do you mean by 'not visible' ? Are there some compiler errors ? Horror and moral terror are your friends. If they are not then they are enemies to be feared.

      B 1 Reply Last reply
      0
      • C Colonel Walter E Kurtz

        Are you using namespaces in file1.h ? What extactly do you mean by 'not visible' ? Are there some compiler errors ? Horror and moral terror are your friends. If they are not then they are enemies to be feared.

        B Offline
        B Offline
        billiam904
        wrote on last edited by
        #3

        No, no namespaces. Boss doesn;t want to use namespaces. Getting undefined class error when compiling on the line where I am insantiating a new class variable: Class2 cClass2; Bill Dennis Orlando, FL

        T C D 3 Replies Last reply
        0
        • B billiam904

          No, no namespaces. Boss doesn;t want to use namespaces. Getting undefined class error when compiling on the line where I am insantiating a new class variable: Class2 cClass2; Bill Dennis Orlando, FL

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          are you sure you're not having trouble with the class name ?? be careful, C/C++ is case sensitive (unlike VB/VB.NET)...


          TOXCCT >>> GEII power
          [toxcct][VisualCalc]

          A 1 Reply Last reply
          0
          • B billiam904

            No, no namespaces. Boss doesn;t want to use namespaces. Getting undefined class error when compiling on the line where I am insantiating a new class variable: Class2 cClass2; Bill Dennis Orlando, FL

            C Offline
            C Offline
            Colonel Walter E Kurtz
            wrote on last edited by
            #5

            Maybe there is a conflict between some #define directives

            #ifndef DONT_INCLUDE_TWICE
            #define DONT_INCLUDE_TWICE

            class Class1
            {

            };

            #endif

            #ifndef DONT_INCLUDE_TWICE
            #define DONT_INCLUDE_TWICE

            class Class2
            {

            };

            #endif

            If DONT_INCLUDE_TWICE is already defined, the definition of Class2 will be skipped. Maybe you can post your header files here... Horror and moral terror are your friends. If they are not then they are enemies to be feared.

            T 1 Reply Last reply
            0
            • C Colonel Walter E Kurtz

              Maybe there is a conflict between some #define directives

              #ifndef DONT_INCLUDE_TWICE
              #define DONT_INCLUDE_TWICE

              class Class1
              {

              };

              #endif

              #ifndef DONT_INCLUDE_TWICE
              #define DONT_INCLUDE_TWICE

              class Class2
              {

              };

              #endif

              If DONT_INCLUDE_TWICE is already defined, the definition of Class2 will be skipped. Maybe you can post your header files here... Horror and moral terror are your friends. If they are not then they are enemies to be feared.

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              but if that was the problem, he would have an error such as "Class already defined"... but the compiler says that the class is NOT defined, even with the header include...


              TOXCCT >>> GEII power
              [toxcct][VisualCalc]

              1 Reply Last reply
              0
              • T toxcct

                are you sure you're not having trouble with the class name ?? be careful, C/C++ is case sensitive (unlike VB/VB.NET)...


                TOXCCT >>> GEII power
                [toxcct][VisualCalc]

                A Offline
                A Offline
                Anonymous
                wrote on last edited by
                #7

                Yes, I'm sure.

                1 Reply Last reply
                0
                • B billiam904

                  No, no namespaces. Boss doesn;t want to use namespaces. Getting undefined class error when compiling on the line where I am insantiating a new class variable: Class2 cClass2; Bill Dennis Orlando, FL

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  billiam904 wrote: Boss doesn;t want to use namespaces. Then don't tell him/her that you can't get away from using the global namespace!


                  "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                  L 1 Reply Last reply
                  0
                  • B billiam904

                    I am a newbie to vc++. I did some C 15 years ago... but, normally, I'm a vb.net guy. However, my current job is VC++ and my boss wants me to place a class inside a .h and .cpp file that already has an existing class. I did this fine but when trying to define an instance of this class from another class, it seems invisible even though I have included the .h file. Here's my code: file1.h class Class1 { // definitions here }; class Class2 { // definitions here }; File1.cpp: #include "file1.h" Class1::SomeFunction() { } Class2::AnotherFunction() { } File 2.h #include "File1.h" class Class3 { Class2 cClass2; // not visible. }; Any ideas? Bill Dennis Orlando, FL

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    I just put your three files into an existing project and it compiled fine. The problem must lie with code that has not been shown.


                    "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                    A 1 Reply Last reply
                    0
                    • D David Crow

                      I just put your three files into an existing project and it compiled fine. The problem must lie with code that has not been shown.


                      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                      A Offline
                      A Offline
                      Anonymous
                      wrote on last edited by
                      #10

                      I am attempting to paste some code here but due to contract restrictions, I can't paste it all. sharewaredlg.h: #if !defined(AFX_SHAREWAREDLG_H__609C8E03_67C4_11D3_A859_00000E00ECA4__INCLUDED_) #define AFX_SHAREWAREDLG_H__609C8E03_67C4_11D3_A859_00000E00ECA4__INCLUDED_ #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 #include "RegisterDlg.h" #include "WavRead.h" class CSharewareDlg : public CDialog { }; class CDemoAudio { private: CWavRead m_cWavRead; public: BYTE *ReadDemoIntoBuffer(); void PlayBuffer(BYTE *pDemoBuffer, WAVEHDR *hdrDemo, DWORD dwDataBufferSize); BYTE *GetDemoBuffer(); DWORD GetDemoSize(); protected: // variables DWORD dwOutDataSize; BYTE* m_pbyDemoBuffer; }; //{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line. #endif // !defined(AFX_SHAREWAREDLG_H__609C8E03_67C4_11D3_A859_00000E00ECA4__INCLUDED_) SingleDlg.h: #if !defined(AFX_SINGLEDLG_H__B2588407_6984_11D1_A856_444553540000__INCLUDED_) #define AFX_SINGLEDLG_H__B2588407_6984_11D1_A856_444553540000__INCLUDED_ #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 // Shareware stuff #include "SharewareDlg.h" struct THREADPARMS_RECORD { CWnd *pWnd; CSingleAlg *pckSingleAlg; CWavWrite *pWavWrite; CWavRecord *pWavRecord; // BD 10/05 ADDED PARM FOR CWAVREAD CWavRead *pWavRead; // BD 10/05 ADDED DEMO PARMS. CDemoAudio *pDemoAudio; // error here undefined class. BYTE *pbyDemoBuffer; int *pnRegLevel; // ========================= BYTE *pbyBuffer; int *pnBufferSize; CString *pstrCurFile; CString *pstrCurFilePath; CEvent *pEvent; CCriticalSection *pCriticalSection; int *pnStop; }; class CSingleDlg : public CDialog { protected: // Program variables CSingleAlg m_ckSingleAlg; CWavWrite m_cWavWrite; CWavRecord m_cWavRecord; CWavRead m_cWavRead; // =========DEMO==================== // Demo variables BD 10/05 CDemoAudio m_cDemoAudio; // Error here. m_cDemoAudio utilizing Undefined class. // ================================= //{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line. #endif // !defined(AFX_SINGLEDLG_H__B2588407_6984_11D1_A856_444553540000__INCLUDED_)

                      A 1 Reply Last reply
                      0
                      • A Anonymous

                        I am attempting to paste some code here but due to contract restrictions, I can't paste it all. sharewaredlg.h: #if !defined(AFX_SHAREWAREDLG_H__609C8E03_67C4_11D3_A859_00000E00ECA4__INCLUDED_) #define AFX_SHAREWAREDLG_H__609C8E03_67C4_11D3_A859_00000E00ECA4__INCLUDED_ #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 #include "RegisterDlg.h" #include "WavRead.h" class CSharewareDlg : public CDialog { }; class CDemoAudio { private: CWavRead m_cWavRead; public: BYTE *ReadDemoIntoBuffer(); void PlayBuffer(BYTE *pDemoBuffer, WAVEHDR *hdrDemo, DWORD dwDataBufferSize); BYTE *GetDemoBuffer(); DWORD GetDemoSize(); protected: // variables DWORD dwOutDataSize; BYTE* m_pbyDemoBuffer; }; //{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line. #endif // !defined(AFX_SHAREWAREDLG_H__609C8E03_67C4_11D3_A859_00000E00ECA4__INCLUDED_) SingleDlg.h: #if !defined(AFX_SINGLEDLG_H__B2588407_6984_11D1_A856_444553540000__INCLUDED_) #define AFX_SINGLEDLG_H__B2588407_6984_11D1_A856_444553540000__INCLUDED_ #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 // Shareware stuff #include "SharewareDlg.h" struct THREADPARMS_RECORD { CWnd *pWnd; CSingleAlg *pckSingleAlg; CWavWrite *pWavWrite; CWavRecord *pWavRecord; // BD 10/05 ADDED PARM FOR CWAVREAD CWavRead *pWavRead; // BD 10/05 ADDED DEMO PARMS. CDemoAudio *pDemoAudio; // error here undefined class. BYTE *pbyDemoBuffer; int *pnRegLevel; // ========================= BYTE *pbyBuffer; int *pnBufferSize; CString *pstrCurFile; CString *pstrCurFilePath; CEvent *pEvent; CCriticalSection *pCriticalSection; int *pnStop; }; class CSingleDlg : public CDialog { protected: // Program variables CSingleAlg m_ckSingleAlg; CWavWrite m_cWavWrite; CWavRecord m_cWavRecord; CWavRead m_cWavRead; // =========DEMO==================== // Demo variables BD 10/05 CDemoAudio m_cDemoAudio; // Error here. m_cDemoAudio utilizing Undefined class. // ================================= //{{AFX_INSERT_LOCATION}} // Microsoft Developer Studio will insert additional declarations immediately before the previous line. #endif // !defined(AFX_SINGLEDLG_H__B2588407_6984_11D1_A856_444553540000__INCLUDED_)

                        A Offline
                        A Offline
                        Anonymous
                        wrote on last edited by
                        #11

                        It's *got* to be something in my SharewareDlg.h file because I moved my class to a separate file and it worked fine. Thanks. Bill Dennis

                        J 1 Reply Last reply
                        0
                        • D David Crow

                          billiam904 wrote: Boss doesn;t want to use namespaces. Then don't tell him/her that you can't get away from using the global namespace!


                          "One must learn from the bite of the fire to leave it alone." - Native American Proverb

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

                          Wish I could. He wants me to do it the way he tells me to do it. Would I have to include the .NET framework if I use namespaces?

                          D 1 Reply Last reply
                          0
                          • A Anonymous

                            It's *got* to be something in my SharewareDlg.h file because I moved my class to a separate file and it worked fine. Thanks. Bill Dennis

                            J Offline
                            J Offline
                            Jose Lamas Rios
                            wrote on last edited by
                            #13

                            Check to see if you have a copy of SharewareDlg.h in some other directory in the include path. You might be adding your class in a different file than the one the compiler is picking. -- jlr http://jlamas.blogspot.com/[^]

                            A 1 Reply Last reply
                            0
                            • J Jose Lamas Rios

                              Check to see if you have a copy of SharewareDlg.h in some other directory in the include path. You might be adding your class in a different file than the one the compiler is picking. -- jlr http://jlamas.blogspot.com/[^]

                              A Offline
                              A Offline
                              Anonymous
                              wrote on last edited by
                              #14

                              I fixed the problem by moving my class to the very beginning of SharewareDlg.h before the if !defined statement. Thanks, guys.

                              J 1 Reply Last reply
                              0
                              • L Lost User

                                Wish I could. He wants me to do it the way he tells me to do it. Would I have to include the .NET framework if I use namespaces?

                                D Offline
                                D Offline
                                David Crow
                                wrote on last edited by
                                #15

                                Bill Dennis wrote: Would I have to include the .NET framework if I use namespaces? No. Namespaces have nothing to do with the .NET framework. It's just the name of a declarative region in your code. All programs use (or have use of) the global namespace. If you use STL, you will see references to the std namespace.


                                "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                                1 Reply Last reply
                                0
                                • A Anonymous

                                  I fixed the problem by moving my class to the very beginning of SharewareDlg.h before the if !defined statement. Thanks, guys.

                                  J Offline
                                  J Offline
                                  Jose Lamas Rios
                                  wrote on last edited by
                                  #16

                                  Anonymous wrote: I fixed the problem by moving my class to the very beginning of SharewareDlg.h before the if !defined statement. I think you fixed the symptom, not the problem... :) Anonymous wrote: Thanks, guys. You're welcome. -- jlr http://jlamas.blogspot.com/[^]

                                  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