Thread: class compiling eror

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    24

    Angry class compiling eror

    Code:
    #include <iostream>
    using namespace std;
    
    class base
    {
    public:
    	base(string name)
    	{	a=name;
    		cout<<"base."<<a<<endl;        //ERROR LINE
    	}
    	void printName(){
    		cout<<a<<endl;           //ERROR LINE
    	}
    protected:
    	string a;
    };
    
    int main()
    {
    	base a("a");
    }
    I get error on the two above indicated lines.I can't figure out my eror. Hope some-one can correct me.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    #include <string>
    ?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    24
    Dave,Thanx for your reply.

    WOW,i thought '#include <string>' is only for string functions/operations.
    I dont see which part of my program does require the string class.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by sujeet1 View Post
    I dont see which part of my program does require the string class.
    Primary and secondary:
    Code:
    #include <iostream>
    using namespace std;
    
    class base
    {
    public:
    	base(string name)
    	{	a=name;
    		cout<<"base."<<a<<endl;        //ERROR LINE
    	}
    	void printName(){
    		cout<<a<<endl;           //ERROR LINE
    	}
    protected:
    	string a;
    };
    
    int main()
    {
    	base a("a");
    }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  2. Mmk, I give up, lets try your way. (Resource Management)
    By Shamino in forum Game Programming
    Replies: 31
    Last Post: 01-18-2006, 09:54 AM
  3. problems compiling a month class
    By kkurz in forum C++ Programming
    Replies: 6
    Last Post: 09-21-2003, 10:49 AM
  4. class errors
    By romeoz in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2003, 07:57 PM