Thread: VC++ Sending data from a structure in one class to a ListBox in a second class.

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    6

    VC++ Sending data from a structure in one class to a ListBox in a second class.

    Hello everyone, I'm building a simple RPG type game and have run into a snag with my inventory. The program is a Dialog based application, the problem I've run into is I've created a seperate class to contain all my item handling code and a listbox on the main dialog to display the names of the items. I'm trying to set the items in the listbox by using:

    Code:
    m_lbInventory.AddString(CItems::PopulateShop(*holder));
    and the function code is:

    Code:
    void CItems::PopulateShop(CString* holder)
    {
    	*holder = ShopList.m_sName;		
    }

    The error I receive is:
    error C2664: 'PopulateShop' : cannot convert parameter 1 from 'const char' to 'class CString *'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

    In that particular case I tried to use pointers in order to get the data, I am not very good with pointers yet and likely did not use them properly. Am I heading in the right direction with the pointers? Or should I be attempting to do this in a completely different way?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Study this and read tutorial
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    void set_string(string &ref_string)
    {
        ref_string = "setting reference parameter";
    }//set_string
    
    void set_string(string *ptr_string)
    {
        *ptr_string = "setting pointer parameter";
    }//set_string
    
    int main()
    {
        string s1, s2;
        set_string(s1);
        set_string(&s2);
    
        cout << "s1 = " << s1 << endl;
        cout << "s2 = " << s2 << endl;
    
        return 1;
    }//main
    Tutorial on pointers

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. data structure design for data aggregation
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-20-2008, 06:43 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. binary tree token problem
    By OldSchool in forum C++ Programming
    Replies: 13
    Last Post: 05-28-2006, 10:42 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Deleting Data within a Structure or class
    By TankCDR in forum C++ Programming
    Replies: 1
    Last Post: 02-01-2002, 10:37 PM