Thread: Accessing something in a Class

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    28

    Accessing something in a Class

    Hey. I have this class
    Code:
    class Railcar
    {
    private:
    	string cartype;
    	int ID;
    	int train;
    public:
    	Railcar(string c, int i, int t): cartype(c),ID(i),train(t) { }
    	Railcar(): cartype(""),ID(0),train(0) { }
    	int IDtrain() { return train; }
    	friend ostream & operator<<(ostream &, Railcar & R);
    };
    and I want to access the train variable and store it onto a queue. But when I write this(where temp is a variable of type Railcar):

    Code:
    	if (X.IDtrain==1)
    	
    	{ one.push_front(temp);
    	  cout<< temp <<endl;		
    	}
    It gives and error that IDtrain doesn't like ==
    So can someone tell me how I get it to use the variable I want?!?

  2. #2
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    Code:
    if (X.IDtrain==1)
    	
    	{ one.push_front(temp);
    	  cout<< temp <<endl;		
    	}
    IDtrain is a function so yuou probably meant IDtrain().
    Code:
    if (X.IDtrain() == 1) {
        one.push_front(temp);
        cout<< temp <<endl;		
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help on class coupling
    By andrea72 in forum C++ Programming
    Replies: 4
    Last Post: 04-17-2011, 10:16 AM
  2. Base-class pointer, accessing object from derived class
    By Korhedron in forum C++ Programming
    Replies: 15
    Last Post: 09-28-2008, 05:30 AM
  3. Replies: 10
    Last Post: 07-26-2008, 08:44 AM
  4. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 02:46 PM