小编Jim*_*Jim的帖子

C++纯虚拟虚空

我一直在阅读有关多态的内容并决定创建一个程序.在基类中,我使它变得抽象,因此派生类可以无错误地使用它.但是当我试图给派生类一个对象时,它会说

2 IntelliSense:不允许抽象类类型为"Son"的对象:line:38

无论如何,这是我的代码

#include <iostream>
#include <string>
using namespace std;

class Father{
protected:
    string prof;
    string name;
public:
    virtual void getProf_getName() = 0; //pure virtual function
    virtual void showProf_showName() = 0; //pure virtual function
};

class Son: public Father{
public:
    Son(){} //creating constructor
    void getProf_getName(string hName, string hProf){
    name = hName;
    prof = hProf;
    }
    void showProf_showName(){
        cout << "The son name is " << name << " and he is a " << prof << endl;
    }
    ~Son(){cout …
Run Code Online (Sandbox Code Playgroud)

c++ polymorphism inheritance class syntax-error

1
推荐指数
1
解决办法
145
查看次数

在指针上调用delete时发生C++崩溃

我用结构和指针( - >)编写了一个小程序.所以我已经声明了一个指向同一结构中另一个对象的对象指针.但是当在应用程序上调用delete时会崩溃.

这是错误

Debug Assertion Failed
File:f:\dd\vctools\crt_bld\self_86x\crt\src\dbgdel.cpp
Line 52
Expression:_BLOCK_TYPE_IS_VALID(pHead -> nBlockUse)
Run Code Online (Sandbox Code Playgroud)

这里也是我的代码(ps当我从程序中删除删除时不会发生此错误)

#include <iostream>
#include <string>
#include <Windows.h>
#include <sstream>
using namespace std;

//declare structure to store info about Billy
struct Son{
    string name;
    string crush;
    int age;
    string hobbies[3];
}Person;

int main(){
    string sAge;
    int i;
    Son* info = new Son;
    info = &Person;
    //user interface
    //Person's name
    cout << "Person's name: ";
    getline(cin, info ->name); //inputs person's name
    //Person's age
    cout << "Person's age: ";
     //inputs …
Run Code Online (Sandbox Code Playgroud)

c++ pointers runtime-error

0
推荐指数
1
解决办法
638
查看次数

C++下标运算符

我写了一段代码,但似乎没有用.每次执行程序时,都会收到此错误

运行时检查失败#2 - 变量'ary'周围的堆栈已损坏

无论如何这里是我的代码(这是一个小代码)

#include <iostream>
using namespace std;

class Arrayz{
private:
    int arry[5];
public:
    Arrayz(){}
    void setInf(){
        for(int i = 0; i < 5; ++i){
            cout << "Enter age of your friends: ";
            cin >> arry[5];
        } 
    }
    const int& operator [](const int pos){
        return arry[pos];
    }
};

int main(){
    Arrayz ary;
    ary.setInf();
    cout << "Here are your friend's age: " << endl;
    for (int i = 0; i < 5; ++i){
        cout << ary[i] << endl;
    } …
Run Code Online (Sandbox Code Playgroud)

c++ class operator-overloading subscript-operator

0
推荐指数
1
解决办法
131
查看次数