The line of Constructor is showing an error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saiavinashiitr
    New Member
    • Mar 2014
    • 16

    The line of Constructor is showing an error

    Code:
    #include <iostream>
    using namespace std;
    class qwerty{
    	
    	public:
    	qwerty();
    	void dispalymessage(){
    		cout<<"Welcome to the world of Programming"<<endl; 
    	}
    };
    int main(){
    	qwerty avinash;
    	avinash.dispalymessage();
    	
    }
    why am i getting an error in the qwerty() line when i run the program?if i remove qwerty() then the program is runing fine...y this is happening so?
  • saiavinashiitr
    New Member
    • Mar 2014
    • 16

    #2
    oh..i got it...the error is that i have kept a semicolon after qwerty()...now i am getting the right answer...Thank u

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      The qwerty constructor has no definition. That is, no code for it.

      BTW: Avoid defining your functions inside the class declaration. This creates a thing called an in-line function which a) bloats your program executable, and b) prevents you from using polymorphism with this class. Unless you know what you are doing, member functions need to be coded outside the class.

      Comment

      Working...