problem with using functions

This is a discussion on problem with using functions within the C++ Programming forums, part of the General Programming Boards category; First, I'll post all the relevant code.. -------------------------------------------------------------------------- #include "classes.h" vector<BluePrint> bprint; vector<Object> object; //================================================== ================================================= void CreateObject(int onum) { ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    35

    problem with using functions

    First, I'll post all the relevant code..

    --------------------------------------------------------------------------

    #include "classes.h"
    vector<BluePrint> bprint;
    vector<Object> object;

    //================================================== =================================================

    void CreateObject(int onum)
    {
    Object NewObject;
    NewObject.ONum = onum;
    NewObject.Hierarchy = GetBPrint(onum).Daughter_Amount + 1;
    bprint[GetBPrintVectorPos(onum)].Daughter_Amount++;


    object.push_back(NewObject);
    cout << "<CreateObject>: Created new object " << onum << endl;
    }

    Object GetObject(int onum, int Heirarchy)
    {
    int X;
    for(X=0;X<object.size();X++)
    {
    if(object[X].ONum == onum)
    {
    if(object[X].Hierarchy == Heirarchy)
    {
    return object[X];
    }
    }
    }
    cout << "<GetObject>: Error: no object found." << endl;
    return object[0];
    }

    int GetObjectVectorPos(int ONum, int Hierarchy)
    {
    int VectorNum;
    for(VectorNum = 0;VectorNum <= object.size();VectorNum++)
    {
    if(ONum == object[VectorNum].ONum)
    {

    if(Hierarchy == object[VectorNum].Hierarchy)
    {
    return VectorNum;
    }
    }
    }
    cout << "<GetObjectVectorPos>: ERROR: No objects found." << endl;
    return 0;
    }

    void PutObjectInObject(Object Item, Object Container)
    {
    GetObject(100, 1).Container = 5;
    Container.Item.push_back(Item.ONum);
    }
    ---------------------------------------------------------------------
    and in an included .h
    -------------------------------
    class Object
    {
    public:
    int ONum;
    int Hierarchy;
    vector<int> Item;
    int Container;
    };
    ------------------------------------------------------------------------------

    using PutObjectInObject gives me this error:
    c:\vc++ projects\objhandler\objects.h(133) : error C2106: '=' : left operand must be l-value
    on the line that has GetObject(100, 1).Container = 5; .
    Anyone know whats wrong? Also, substituting GetObject(100, 1) for object[any number] will fix it. However, I can't do that for other reasons.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    First off, use code tags. Second, either return a pointer or reference to the object
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with functions
    By saliya in forum C Programming
    Replies: 1
    Last Post: 11-05-2007, 09:36 PM
  2. Problem with system(), execl(), etc. functions
    By nickkrym in forum C Programming
    Replies: 5
    Last Post: 05-12-2007, 08:04 AM
  3. Problem: Functions
    By Dmitri in forum C Programming
    Replies: 21
    Last Post: 11-06-2005, 09:40 AM
  4. Problem with pointers and functions
    By Kheila in forum C++ Programming
    Replies: 5
    Last Post: 10-13-2005, 12:40 PM
  5. Problem with functions
    By lizardking3 in forum C++ Programming
    Replies: 4
    Last Post: 09-22-2003, 04:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21