OO problem

This is a discussion on OO problem within the C++ Programming forums, part of the General Programming Boards category; Hello, Can you please show me the error in this: Code: // header.h // each class have a function that ...

  1. #1
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    386

    OO problem

    Hello,
    Can you please show me the error in this:
    Code:
    // header.h
    // each class have a function that takes a pointer to an object of the other class
    class c1{
    
    	void f1(c2* c2p);
    
    	};
    
    class c2{
    
    	void f2(c1* c1p);
    
    	};
    
    // implementation
    #include "header.h"
    
    void c1::f1(c2* c2p){
    
    	};
    
    void c2::f2(c1* c1p){
    
    	};
    
    //main
    void main(){
    	c1 ca;
    	c2 cb;
    	}
    I get errors:
    C2061: syntax error : identifier 'c2'
    C2511: 'f1' : overloaded member function 'void (class c2 *)' not found in 'c1'

    Thanks in advance.

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Put class c2; on the line just above your c1 class declaration. At the point when the compiler is looking at the c1 declaration, it has never heard of c2 and doesn't know what that is.

    Also note that it should be int main(), not void.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

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