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. Problem passing a Reference through multiple functions

Problem passing a Reference through multiple functions

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestionworkspace
2 Posts 2 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.
  • J Offline
    J Offline
    jblau
    wrote on last edited by
    #1

    I am trying to pass a reference through a couple of layers of functions, and I am getting a C2664 Error. Here is my setup: I have a class [ c_ClassOne ] which contains a pointer to an object [ p_MyObject ]. I have a second class [ c_ClassTwo ] which has a function [ FunctionOne(MYOBJECTTYPE* myObject) ] I have a third class [ c_ClassThree ] which also has a function [ FunctionTwo(MYOBJECTTYPE* myObject) ] I then try to pass the reference to the pointer p_MyObject from c_ClassOne to be used within FunctionTwo. So in a function within c_ClassOne I create an instance of c_ClassTwo [ myClassTwo ] I then pass a reference to p_MyObject as follows: myClassTwo.FunctionOne(&p_MyObject); Then within FunctionOne, I create an Instance of c_ClassThree [ myClassThree ] I then attempt to once again pass the reference to p_MyObject: myClassThree.FunctionTwo(&p_MyObject); On that line I get the following error: error C2664: 'CD3DInitialize::Enumerate' : cannot convert parameter 1 from 'LPDIRECT3D9 ** ' to 'LPDIRECT3D9' Note: LPDIRECT3D9 is the Object Type of p_MyObject. Can anyone explain what I am doing wrong, and help me understand how to do it correctly? Thanks, Jody

    realJSOPR 1 Reply Last reply
    0
    • J jblau

      I am trying to pass a reference through a couple of layers of functions, and I am getting a C2664 Error. Here is my setup: I have a class [ c_ClassOne ] which contains a pointer to an object [ p_MyObject ]. I have a second class [ c_ClassTwo ] which has a function [ FunctionOne(MYOBJECTTYPE* myObject) ] I have a third class [ c_ClassThree ] which also has a function [ FunctionTwo(MYOBJECTTYPE* myObject) ] I then try to pass the reference to the pointer p_MyObject from c_ClassOne to be used within FunctionTwo. So in a function within c_ClassOne I create an instance of c_ClassTwo [ myClassTwo ] I then pass a reference to p_MyObject as follows: myClassTwo.FunctionOne(&p_MyObject); Then within FunctionOne, I create an Instance of c_ClassThree [ myClassThree ] I then attempt to once again pass the reference to p_MyObject: myClassThree.FunctionTwo(&p_MyObject); On that line I get the following error: error C2664: 'CD3DInitialize::Enumerate' : cannot convert parameter 1 from 'LPDIRECT3D9 ** ' to 'LPDIRECT3D9' Note: LPDIRECT3D9 is the Object Type of p_MyObject. Can anyone explain what I am doing wrong, and help me understand how to do it correctly? Thanks, Jody

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #2

      Just pass it like this: myClassTwo.FunctionOne(p_MyObject); myClassThree.FunctionOne(p_MyObject); Your functions are accepting pointers, and the object you're passing is a pointer. There is no need to dereference it.

      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

      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