Solved

class CreateAndDestroy

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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.
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.

758 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

19 Experts available now in Live!

Get 1:1 Help Now