Skip to content

"We received the following error when we ran your code:" but no error is following #2199

@bakaiadam

Description

@bakaiadam

I'm on the site: https://exercism.org/tracks/cpp/exercises/circular-buffer/edit

My .hh source code is:

#if !defined(CIRCULAR_BUFFER_H)
#define CIRCULAR_BUFFER_H
#include <vector>
#include  <stdexcept>
using namespace std;
namespace circular_buffer {
template<typename T>
class  circular_buffer
{

public:
int pos=0;
int writepos=0;
int len=0;
vector<T> elems;
int num;
circular_buffer(int num): elems(num)
{
    num=num;
}





T read()
{
    if (len==0)
        throw domain_error("alma");
    len--;
    T ret= elems[pos];
    pos=(pos+1)%num;
    return ret;
    
}

void write(T a)
{
    if (len==num)
        throw domain_error("alma");
    len++;
 
    
    writepos=(writepos+1)%num;
    elems[writepos]=a;
    
    
}

void clear()
{
    len=0;
    
}

void overwrite(T a)
{
       if (len==num)
       {}
    else
    len++;
 
    
    writepos=(writepos+1)%num;
    elems[writepos]=a;

    
}


};

}  // namespace circular_buffer

#endif // CIRCULAR_BUFFER_H

The .cc source code is the default

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions