Object array

Page 1 of 1

3 Replies - 225 Views - Last Post: 02 February 2013 - 08:01 AM Rate Topic: -----

#1 sanwall  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 57
  • Joined: 07-March 10

Object array

Posted 02 February 2013 - 04:48 AM

The program just crashes without giving any output, explain ? :dontgetit:
using namespace std;
class book
{
private:
	char *author[3];
public:
	book(char *a)
	{
		for(int i=0;i<=2;i++)
			{
			    strcpy(author[i],a);
              	            cout<<*(author+i)<<endl;
		    }
	}
};
int main()
{	
	book b[3]={book("Hi 2 all"),book("Have fun"),book("u all")};
	getch();
	return 0;
}




Is This A Good Question/Topic? 0
  • +

Replies To: Object array

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3718
  • View blog
  • Posts: 5,989
  • Joined: 08-June 10

Re: Object array

Posted 02 February 2013 - 07:56 AM

I've moved this to the C/C++ forum. Please post your help requests in the appropriate language help forums.
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: Object array

Posted 02 February 2013 - 07:59 AM

There would have been an error message that went along with the crash. What did it say?

Are you sure its really crashing and not just completing then closing?
Instead of getch() why not try getting a full line. That way it requires the [ENTER] key and not just any key still stuck in the keyboard buffer.
Was This Post Helpful? 1
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 4025
  • View blog
  • Posts: 12,423
  • Joined: 25-December 09

Re: Object array

Posted 02 February 2013 - 08:01 AM

Duplicate topic, Closed


Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1