Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

class CreateAndDestroy

Posted on 2004-04-24
3
Medium Priority
?
264 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 1000 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 1000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

885 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