| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3274 人关注过本帖
标题:请教大家一个问题
只看楼主 加入收藏
荀减一
Rank: 1
等 级:新手上路
帖 子:19
专家分:2
注 册:2016-2-27
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:1 
请教大家一个问题
0x00FC7F7D 处有未经处理的异常(在 作业4.15(1).exe 中):  0xC0000005:  写入位置 0xCCCCCCCC 时发生访问冲突。
这个问题是什么造成的?
代码如下(一个判断字符串是否为回文的程序)

#include<iostream>
#include<string>
using namespace std;
#define defaultSize 20

void Assert(bool val, string  s) {
    if (!val) { // Assertion failed  -- close the   program
        cout << "Assertion Failed:  " << s << endl;
        exit(-1);
    }
};

template <typename E> class Stack
{
private:
    void operator = (const Stack&){};
    Stack(const Stack&){}

public:
    Stack(){}
    virtual ~Stack(){}

    virtual void clear() = 0;
    virtual void push(const E& it) = 0;
    virtual E pop() = 0;
    virtual const E & topValue() const = 0;
    virtual int length() const = 0;
};

template<typename E>class Queue
{
private:
    void operator = (const Queue&){}
    Queue(const Queue&){}
public:
    Queue(){}
    virtual ~Queue(){}

    virtual void clear() = 0;
    virtual void enqueue(const E&) = 0;
    virtual E dequeue() = 0;
    virtual const E&frontValue()const = 0;
    virtual int length() const = 0;
};
// Array-based queue implementation
template <typename E> class AQueue : public Queue<E> {
private:
    int maxSize; // Maximum size of queue
    int front; // Index of front element
    int rear; // Index of rear element
    E *listArray; // Array holding queue elements

public:
    AQueue(int size = defaultSize) { //Constructor   
        // Make list array one position larger for empty slot
        maxSize = size + 1;
        rear = 0;
        front = 1;
        listArray = new E[maxSize];
    };

    ~AQueue() { delete[] listArray; } // Destructor

    void clear() { rear = 0; front = 1; } // Reinitialize

    void enqueue(const E& it) { // Put "it" in queue
        Assert(((rear + 2) % maxSize) != front, "Queue is full");
        rear = (rear + 1) % maxSize; // Circular increment
        listArray[rear] = it;
    }

    E dequeue() { // Take element out
        Assert(length() != 0, "Queue is empty");
        E it = listArray[front];
        front = (front + 1) % maxSize; // Circular increment
        return it;
    }

    const E& frontValue() const { // Get front value
        Assert(length() != 0, "Queue is empty");
        return listArray[front];
    }

    virtual int length() const // Return length
    {
        return ((rear + maxSize) - front + 1) % maxSize;
    }
};


// Array-based stack implementation
template <typename E> class AStack : public Stack<E> {
private:
    int maxSize; // Maximum size of stack
    int top; // Index for top element
    E *listArray; // Array holding stack elements

public:
    AStack(int size = defaultSize) // Constructor
    {
        maxSize = size; top = 0; listArray = new E[size];
    }

    ~AStack() { delete[] listArray; } // Destructor

    void clear() { top = 0; } // Reinitialize

    void push(const E& it) { // Put "it" on stack
        Assert(top != maxSize, "Stack is full");
        listArray[top++] = it;
    }

    E pop() { // Pop top element
        Assert(top != 0, "Stack is empty");
        return listArray[--top];
    }

    const E& topValue() const { // Return top element
        Assert(top != 0, "Stack is empty");
        return listArray[top - 1];
    }
    int length() const { return top; } // Return length
};


int main()
{
    int n, i;
    AStack <char> aStack[20];
    AQueue <char> aQueue[20];
    char S[20];

    cout << "判断一个字符串是否为回文" << endl;
    cout << "请输入一串字符(不超过20个元素)" << endl;
    cin >> S;
    n = sizeof(S[20]);
    for (i = 0; i < n; i++)
    {
        aStack[20].push(S[i]);
        aQueue[20].enqueue(S[i]);
    }
    for (i = 0; i < n; i++)
    {
        if (aStack[20].topValue() != aQueue[20].frontValue())
        {
            cout << "false" << endl;
        }break;
        
        aQueue[20].dequeue() && aStack[20].pop();
    }


}
搜索更多相关主题的帖子: private include Failed failed 字符串 
2016-04-11 00:00
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:20 
除了main函数,写的几乎没有错。

Class 'AQueue' has virtual method 'length' but non-virtual destructor

重写main函数吧,应该只有main函数是你自己写的。。。


[fly]存在即是合理[/fly]
2016-04-11 09:21
快速回复:请教大家一个问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015100 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved