Thread: Class issue

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

    Class issue

    This gives me an error about not recognizing railcar. What am I doing wrong?
    Code:
    //
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <cmath>
    #include <stack>
    #include <ctime>
    #include <deque>
    
    using namespace std;
    
    //WORKAROUND
    	class railcar;
    	ostream & operator<<(ostream &, railcar & );
    //WORKAROUND
    
    
    
    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 id; }
    	
    	friend ostream & operator << (ostream &, railcar & r);
    	
    	typedef long_train deque <railcar *>;
    
    	railcar :: railcar (string c, int i, int t)
    	{ 
    	  railcar=r;	
    	  cartype=c;
    	  id=i;
    	  train=t;
    	}
    };
    
    ostream & operator<<(ostream & ostr, railcar & r)
    
    {
    	ostr << r.cartype << "   " << r.id << "    " << r.train;
    	return ostr;
    }
    
    
    
    int  ()
    {
    	ofstream car_file("railcars.txt");
    	std::cout << car_file << endl;
    
    
    
    
    
    
    
    
    
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2003
    Posts
    3

    Re: Class issue

    Originally posted by PunkyBunny300
    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 id; }
    	
    	friend ostream & operator << (ostream &, railcar & r);
    	
    	typedef long_train deque <railcar *>;
    
    	railcar :: railcar (string c, int i, int t)
    	{ 
    	  railcar=r;	
    	  cartype=c;
    	  id=i;
    	  train=t;
    	}
    };
    at the start it should be
    Code:
    class railcar
    {
    ...
    };
    Hope that helps

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Whoa! What happened to main?

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    28
    thats all the declarations before main.

  5. #5
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    No, I mean:
    Code:
    int  ()
    {
    	ofstream car_file("railcars.txt");
    	std::cout << car_file << endl;
    
    
    
    
    
    
    
    
    
    return 0;
    }
    What happened to main as in "where'd it go"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Inherite nonvirtual class functionality
    By DrSnuggles in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2009, 01:52 PM
  3. Need help to build network class
    By weeb0 in forum C++ Programming
    Replies: 0
    Last Post: 02-01-2006, 11:33 AM
  4. class errors
    By romeoz in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2003, 07:57 PM