Click here to Skip to main content
15,922,166 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC Grid Control Exception in Release Build Only! Pin
PJ Arends12-Mar-05 17:41
professionalPJ Arends12-Mar-05 17:41 
GeneralRe: MFC Grid Control Exception in Release Build Only! Pin
jarbus13-Mar-05 9:02
jarbus13-Mar-05 9:02 
GeneralRe: MFC Grid Control Exception in Release Build Only! Pin
PJ Arends13-Mar-05 10:58
professionalPJ Arends13-Mar-05 10:58 
GeneralRe: MFC Grid Control Exception in Release Build Only! Pin
PJ Arends13-Mar-05 11:10
professionalPJ Arends13-Mar-05 11:10 
GeneralC++ Dll Pin
Daniel Kanev12-Mar-05 9:53
Daniel Kanev12-Mar-05 9:53 
GeneralRe: C++ Dll Pin
YaronNir12-Mar-05 11:25
YaronNir12-Mar-05 11:25 
GeneralRe: C++ Dll Pin
John R. Shaw12-Mar-05 13:14
John R. Shaw12-Mar-05 13:14 
GeneralInheritance & Derived Classes Pin
tnvols12-Mar-05 9:48
tnvols12-Mar-05 9:48 
I'm stuck, I have a base class String, derived class Pstring, and trying to develop another derived class Pstring2. Pstring2 needs a function called left. Main will call the function by Text2.left(Text1,N) // Text2 is assigned the leftmost N characters from Text1. I'm having a hard time understanding how to connect Pstring2 to Pstring and String base class. Left member function of Pstring2 will carve out the left most 10 characters assigned to an object. The code I have so far is noted below. Can you give me some help?



#include <iostream>
using namespace std;
#include <cstring> //for strcpy(), etc.
#include <conio.h> //For getch()
////////////////////////////////////////////////////////////////
class String //user-defined string type
{
protected:
enum { SZ = 80 }; //size of all String objects
char str[SZ]; //holds a C-string
public:
String() //no-arg constructor
{ str[0] = '\0'; }
String( char s[] ) //1-arg constructor
{ strcpy(str,s); } //convert C-string to String
void display() //display the String
{ cout << str; }
operator char*()
{ return str;}
};

class Pstring : public String
{
public:
Pstring(char s[]): String(s)
{ if(strlen(s)>(SZ-1)){
strncpy(str,s,79);
str[79] = '\0';
}
else
String(s);
}
};

//class Pstring2 : public Pstring
//{
// public:
// Pstring2() : Pstring



//};
////////////////////////////////////////////////////////////////
int main()
{
cout << "THIS SENTENCE IS SHORTER THAN SZ:" << endl;
Pstring2 s1 = "Never read the instructions.";
s1.display();
cout << endl <<"THIS SENTENCE IS LONGER THAN SZ:" << endl;
Pstring2 s2 = "I would have to say that the greatest single achievement "
"of the American medica";
s2.display();
cout << endl <<"THIS SENTENCE DEMONSTRATES THE LEFT, MID AND RIGHT FUNCTIONS:" << endl;
Pstring2 s3 = "A long time ago in a galaxy far, far away.";
s3.display();



getch();
return 0;
}

Thanks!
GeneralRe: Inheritance &amp; Derived Classes Pin
tnvols12-Mar-05 13:01
tnvols12-Mar-05 13:01 
Questionhow to communicate with a web site Pin
Mohsen Saad12-Mar-05 6:43
Mohsen Saad12-Mar-05 6:43 
AnswerRe: how to communicate with a web site Pin
Ravi Bhavnani12-Mar-05 10:14
professionalRavi Bhavnani12-Mar-05 10:14 
GeneralWin32 API and FindWindow Pin
3Dizard12-Mar-05 5:19
3Dizard12-Mar-05 5:19 
GeneralRe: Win32 API and FindWindow Pin
Mohsen Saad13-Mar-05 6:05
Mohsen Saad13-Mar-05 6:05 
GeneralRe: Win32 API and FindWindow Pin
David Crow14-Mar-05 5:59
David Crow14-Mar-05 5:59 
Generallinking of vc++ program to another vc++ prog Pin
mhay_nineteen@yahoo.com12-Mar-05 0:51
sussmhay_nineteen@yahoo.com12-Mar-05 0:51 
GeneralRe: linking of vc++ program to another vc++ prog Pin
deldeep12-Mar-05 1:17
deldeep12-Mar-05 1:17 
Questiondll problem? Pin
murali_utr11-Mar-05 23:26
murali_utr11-Mar-05 23:26 
AnswerRe: dll problem? Pin
YaronNir12-Mar-05 11:28
YaronNir12-Mar-05 11:28 
GeneralPlease help, i got problem with memory allocation Pin
Rassul Yunussov11-Mar-05 22:58
Rassul Yunussov11-Mar-05 22:58 
GeneralWorking with MS Word Pin
Zero_divide_111-Mar-05 20:44
Zero_divide_111-Mar-05 20:44 
Generaldiference between C++ and VC++ Pin
Anonymous11-Mar-05 19:42
Anonymous11-Mar-05 19:42 
GeneralRe: diference between C++ and VC++ Pin
Zero_divide_111-Mar-05 20:26
Zero_divide_111-Mar-05 20:26 
GeneralRe: diference between C++ and VC++ Pin
markkuk12-Mar-05 0:45
markkuk12-Mar-05 0:45 
GeneralRe: diference between C++ and VC++ Pin
deldeep12-Mar-05 2:59
deldeep12-Mar-05 2:59 
GeneralRe: diference between C++ and VC++ Pin
John R. Shaw12-Mar-05 13:46
John R. Shaw12-Mar-05 13:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.