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. Access violation problem

Access violation problem

Scheduled Pinned Locked Moved C / C++ / MFC
help
12 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.
  • S singersinger

    hello, i have a 2 classes each have a couple of functions and variable the problem is: when i want to access a variable from class B inside a function in class A it come up with Unhandled Exception says: unhandled exception in "program name": 0xC0000005: Access Violation class A { //////// B* p_channel; ///////// inline BOOL StartIVR(){ p_channel->m_started = TRUE; // error occur here} /////// } class B { ///////// BOOL m_started ; /////// } also any other access to any member in class B will result with the same exception plz if anybody have any idea abt what's goin' on with this code, feel free to tell me :=) thnx alot for ur time and concern

    E Offline
    E Offline
    Eytukan
    wrote on last edited by
    #3

    Define your class B on top A. and see to that you've specified "protected" or "public" to your BOOL m_started;


    --[:jig:]-- [My Current Status] Link2006 wrote:Let's take it outside of CP Jeremy : Please don't.I would love to see this.I'm making the popcorn already.

    1 Reply Last reply
    0
    • S singersinger

      hello, i have a 2 classes each have a couple of functions and variable the problem is: when i want to access a variable from class B inside a function in class A it come up with Unhandled Exception says: unhandled exception in "program name": 0xC0000005: Access Violation class A { //////// B* p_channel; ///////// inline BOOL StartIVR(){ p_channel->m_started = TRUE; // error occur here} /////// } class B { ///////// BOOL m_started ; /////// } also any other access to any member in class B will result with the same exception plz if anybody have any idea abt what's goin' on with this code, feel free to tell me :=) thnx alot for ur time and concern

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #4

      p_channel is an uninitialized pointer. Time to pick up the C++ book.

      -- Broadcast simultaneously one year in the future

      S 1 Reply Last reply
      0
      • S singersinger

        hello, i have a 2 classes each have a couple of functions and variable the problem is: when i want to access a variable from class B inside a function in class A it come up with Unhandled Exception says: unhandled exception in "program name": 0xC0000005: Access Violation class A { //////// B* p_channel; ///////// inline BOOL StartIVR(){ p_channel->m_started = TRUE; // error occur here} /////// } class B { ///////// BOOL m_started ; /////// } also any other access to any member in class B will result with the same exception plz if anybody have any idea abt what's goin' on with this code, feel free to tell me :=) thnx alot for ur time and concern

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #5

        How to initialized p_channel?


        WhiteSky


        E 1 Reply Last reply
        0
        • H Hamid Taebi

          How to initialized p_channel?


          WhiteSky


          E Offline
          E Offline
          Eytukan
          wrote on last edited by
          #6

          ??whitesky?:~


          --[:jig:]-- [My Current Status] Link2006 wrote:Let's take it outside of CP Jeremy : Please don't.I would love to see this.I'm making the popcorn already.

          H 1 Reply Last reply
          0
          • J Jorgen Sigvardsson

            p_channel is an uninitialized pointer. Time to pick up the C++ book.

            -- Broadcast simultaneously one year in the future

            S Offline
            S Offline
            singersinger
            wrote on last edited by
            #7

            the thing is that this p_channel is assigned a value in the construction of the class, meaning that the constructor is responsible for initializing this pointer so when i call p_channel->"whatever" it is supposed that it is already initialized

            E 1 Reply Last reply
            0
            • E Eytukan

              ??whitesky?:~


              --[:jig:]-- [My Current Status] Link2006 wrote:Let's take it outside of CP Jeremy : Please don't.I would love to see this.I'm making the popcorn already.

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #8

              Why:doh:


              WhiteSky


              E 1 Reply Last reply
              0
              • S singersinger

                hello, i have a 2 classes each have a couple of functions and variable the problem is: when i want to access a variable from class B inside a function in class A it come up with Unhandled Exception says: unhandled exception in "program name": 0xC0000005: Access Violation class A { //////// B* p_channel; ///////// inline BOOL StartIVR(){ p_channel->m_started = TRUE; // error occur here} /////// } class B { ///////// BOOL m_started ; /////// } also any other access to any member in class B will result with the same exception plz if anybody have any idea abt what's goin' on with this code, feel free to tell me :=) thnx alot for ur time and concern

                S Offline
                S Offline
                singersinger
                wrote on last edited by
                #9

                Yes guys i was wrong i was passing the pointer to the constructor without initializing it this is wierd, how did i forget to initialize a pointer. thnx 4 u help it was really useful. :=)

                1 Reply Last reply
                0
                • H Hamid Taebi

                  Why:doh:


                  WhiteSky


                  E Offline
                  E Offline
                  Eytukan
                  wrote on last edited by
                  #10

                  Your post looked like you are asking how to initialize a pointer ;P :-D


                  --[:jig:]-- [My Current Status] Link2006 wrote:Let's take it outside of CP Jeremy : Please don't.I would love to see this.I'm making the popcorn already.

                  H 1 Reply Last reply
                  0
                  • S singersinger

                    the thing is that this p_channel is assigned a value in the construction of the class, meaning that the constructor is responsible for initializing this pointer so when i call p_channel->"whatever" it is supposed that it is already initialized

                    E Offline
                    E Offline
                    Eytukan
                    wrote on last edited by
                    #11

                    what?? you say B* p_channel then how can it be ?You should've put B* p_channel=new B; Even I didn't notice it.


                    --[:jig:]-- [My Current Status] Link2006 wrote:Let's take it outside of CP Jeremy : Please don't.I would love to see this.I'm making the popcorn already.

                    1 Reply Last reply
                    0
                    • E Eytukan

                      Your post looked like you are asking how to initialize a pointer ;P :-D


                      --[:jig:]-- [My Current Status] Link2006 wrote:Let's take it outside of CP Jeremy : Please don't.I would love to see this.I'm making the popcorn already.

                      H Offline
                      H Offline
                      Hamid Taebi
                      wrote on last edited by
                      #12

                      wow really:-D


                      WhiteSky


                      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