Solved

class CreateAndDestroy

Posted on 2004-04-24
3
240 Views
Last Modified: 2010-04-01
// CreateAndDestroy.cpp

#include <iostream>

using namespace std;

class CreateAndDestroy {

   int objectID;
   char *message;

public:

   CreateAndDestroy(int, char *);
   ~CreateAndDestroy();

};

CreateAndDestroy::CreateAndDestroy(int objectNumber, char *messagePtr)
{
   objectID = objectNumber;
   message = messagePtr;

   cout << "Object " << objectID << "  constructor runs   " << message << endl;

}

CreateAndDestroy::~CreateAndDestroy()
{
   cout << (objectID == 1 || objectID == 6 ? "\n" : "");

   cout << "Object " << objectID << "   destructor runs   " << message << endl;

}

void create(void);
CreateAndDestroy first(1, "(global before main)");

int main()
{
   cout << "\nMAIN FUNCTION: EXECUTION BEGINS" << endl;

   CreateAndDestroy second(2, "(local automatic in main)");

   static CreateAndDestroy third(3, "(local static in main)");

   create();

   cout << "\nMAIN FUNCTION: EXECUTION RESUMES" << endl;

   CreateAndDestroy fourth(4, "(local automatic in main)");

   cout << "\nMAIN FUNCTION: EXECUTION ENDS" << endl;

   return 0;

}

void create(void)
{
   cout << "\nCREATE FUNCTION: EXECUTION BEGINS" << endl;

   CreateAndDestroy fifth(5, "(local automatic in create)");

   static CreateAndDestroy sixth(6, "(local static in create)");

   CreateAndDestroy seventh(7, "(local automatic in create)");

   cout << "\nCREATE FUNCTION: EXECUTION ENDS\" << endl;

}      

output:

CreateAndDestroy.cpp:69: unterminated string or character constant
CreateAndDestroy.cpp:69: possible real start of unterminated constant
0
Comment
Question by:edelossantos
3 Comments
 
LVL 14

Accepted Solution

by:
Farzad Akbarnejad earned 250 total points
ID: 10906515
>cout << "\nCREATE FUNCTION: EXECUTION ENDS\" << endl;

remove '\' character or duplicate it in last line of your code:

change to

cout << "\nCREATE FUNCTION: EXECUTION ENDS" << endl;

or

cout << "\nCREATE FUNCTION: EXECUTION ENDS\\" << endl;


Thanks
-FA

0
 
LVL 11

Assisted Solution

by:avizit
avizit earned 250 total points
ID: 10906739

cout << "\nCREATE FUNCTION: EXECUTION ENDS\" << endl;

basically you have escaped the ending double quote by the backslash and hence your string is no unterminated so you need one more " or you coudl remove the \

so any of following would work


cout << "\nCREATE FUNCTION: EXECUTION ENDS" << endl;
or
cout << "\nCREATE FUNCTION: EXECUTION ENDS\n" << endl;

( i guess you intended the second solution cos your solution starts with "\n  .. but you may not need it as you have an endl anyway atthe end,

/abhijit/
0
 

Author Comment

by:edelossantos
ID: 10907810
Both solutions were outstanding!!!!!!!!!!!!!!!!!!!!!!!!!!!!  Thank you very much.  Del
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now