delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/01/15/22:15:21

Date: 15 Jan 1994 19:02:04 -0800 (PST)
From: Gregory Eakin <XGEAKIN AT CCVAX DOT FULLERTON DOT EDU>
Subject: Re: no 'new' runtime error
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Cc: mmoss AT panix DOT com

Dear Mathew:
 
The problem is strcpy() in the Command class creator.  It needs
a place to copy name to.  Here is a working example of your code:
 
/////////////////////////////////////
#include <stdio.h>
#include <string.h>
 
typedef int classes;            // Whatever classes are.
 
class Command {
    classes     _cl;
    char        _name[80];      // The string goes here.
 
protected:
    Command(classes cl, char* name) : _cl(cl) { strcpy(_name, name); }
public:
    virtual int Perform() = 0;
    virtual char* isA() { return "Command"; }
};
 
class C_create : public Command {
public:
    C_create(classes cl, char* name) : Command(cl, name) { }
    virtual char* isA() { return "C_create"; }
    virtual int Perform() { }
};
 
int main(int argv, char* argc[]) {
    classes temp_cl;        // dummy classes.
    printf("About to create C_create:\n");
    C_create *temp = new C_create(temp_cl, argc[1]);  // A pointer
    C_create temp2(temp_cl, argc[1]);                 // or a local var
    printf("Created C_create successfully!\n");
}
 
/////////////////////////////////////////////////
 
No, there is not a new bug for the new function.
 
-- Greg

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019