Solved

class CreateAndDestroy

Posted on 2004-04-24
3
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

728 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