Thread: Classes

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    8

    Classes

    Code:
    class one {
    	public:
    		void test(two t) {
    
    		}
    };
    
    class two {
    	public:
    		void testt(one o) {
    
    		}
    };
    
    int main() {
    	return 0;
    }

    this gives the following error in visual c++ :

    Code:
    (3)error C2061: syntax error : identifier 'two'

    how do i fix such a thing.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Forward declare the two class, and the define one::test outside of the class definition, e.g.,
    Code:
    class two;
    
    class one {
    public:
        void test(two t);
    };
    
    class two {
    public:
        void testt(one o) {
    
        }
    };
    
    int main() {
        return 0;
    }
    
    void one::test(two t) {
    
    }
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    8
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple classes question
    By TriKri in forum C++ Programming
    Replies: 20
    Last Post: 06-11-2010, 04:03 PM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM