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
Solved

class CreateAndDestroy

Posted on 2004-04-24
3
243 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

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

Suggested Solutions

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 video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

838 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