Accessing something in a Class

This is a discussion on Accessing something in a Class within the C++ Programming forums, part of the General Programming Boards category; Hey. I have this class Code: class Railcar { private: string cartype; int ID; int train; public: Railcar(string c, int ...

  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
    lyx
    lyx is offline
    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, 11:16 AM
  2. Base-class pointer, accessing object from derived class
    By Korhedron in forum C++ Programming
    Replies: 15
    Last Post: 09-28-2008, 06:30 AM
  3. Replies: 10
    Last Post: 07-26-2008, 09:44 AM
  4. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 03:46 PM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

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