阿西吧 发表于 2017-7-4 10:15:19

Debug error abnormal program termination

c++小甲鱼第37课,自己写的代码也出现abnormal program termination,小甲鱼的源代码编译也出现这个错误abnormal program termination

阿西吧 发表于 2017-7-4 10:24:54

小甲鱼课件的代码,我在VC下不能运行
#include <iostream>
#include <string>

class Company
{
public:
    Company(std::string theName, std::string product);
    virtual void printInfo();

protected:
    std::string name;
    std::string product;
};

class TechCompany : public Company
{
public:
    TechCompany(std::string theName, std::string product);
    virtual void printInfo();
};

Company::Company(std::string theName, std::string product)
{
    name = theName;
    this->product = product;
}

void Company::printInfo()
{
    std::cout << "这个公司的名字叫:" << name <<
    "正在生产" << product << "\n";
}

TechCompany::TechCompany(std::string theName, std::string product) : Company(theName, product)
{
}

void TechCompany::printInfo()
{
    std::cout << name << "公司大量生产了 " << product << "这款产品!\n";
}

int main()
{
    Company *company = new Company("APPLE", "Iphone");
    TechCompany *tecCompany = dynamic_cast<TechCompany *>(company);

    if( tecCompany != NULL )
    {
      std::cout << "成功!\n";
    }
    else
    {
      std::cout << "悲催!\n";
    }

    delete company;

    company = NULL;
    tecCompany = NULL;

    return 0;
}
页: [1]
查看完整版本: Debug error abnormal program termination