Error ?

This is a discussion on Error ? within the C++ Programming forums, part of the General Programming Boards category; Code: class B { public: virtual void display() { cout << No function display defined in this class\n; }; class ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    36

    Error ?

    Code:
    class B 
    { 
    public: 
    virtual void display() 
    { 
    cout << No function display defined in this class\n; 
    }; 
    class D: B {}; 
    
    void main() 
    { 
     D d; 
    d.display(); 
    }

    Whts the error in above code ??

    :-((

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,346
    Change D to a struct.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    36
    Code:
    class D: B {}; 
    
    to
    
    class struct B {};

    ??

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    We're not human compilers. At least make an honest effort before asking us questions. What you posted has a number of mistakes and issues, and it indicates you have no clue what you're doing. Don't dump garbage code at us without giving us anything to go on.

    Here's a free pass:

    Code:
    #include <iostream>
    
    class B
    {
    	public: 
    		virtual void display() 
    		{
    			std::cout << "No function display defined in this class\n"; 
    		}
    };
    class D : public B
    {
    	
    };
    
    int main() 
    { 
    	D d; 
    	d.display(); 
    }
    Go learn to code for real, and make sure you're not lazy about it. We're willing to help, of course, but if you don't have a good foundation in something, we can't point you in the right direction. That requires you to learn.

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,352
    When code is indented properly, all things become clear.

    Quote Originally Posted by kolucoms6 View Post
    Code:
    class B 
    { 
    public: 
        virtual void display() 
        { 
            cout << “No function display defined in this class\n”; 
        } // the semicolon doesn't belong here ;
    }; // this closing brace and semicolon was entirely missing

    Whts the error in above code ??

    :-((

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. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

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