Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7560507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:55:17+00:00 2026-05-30T12:55:17+00:00

I am having erratic issue with my copy constructor. I have a class MyData

  • 0

I am having erratic issue with my copy constructor.

I have a class MyData as follows:

class MyData
{
    private:
    std::vector<double> wavelength;
    std::vector<double> amplitude;

    public:
    MyData::MyData(void) {}

    MyData::MyData(const MyData &cSource)
      : wavelength(cSource.wavelength), amplitude(cSource.amplitude)
    {}
}

In my main program, I am inserting MyData objects into a ring buffer. This is how I am reading it back in main:

MyData data;
data = removeq(&q);

The problem is that sometimes the copied data is missing some values. Etc. if the original size of wavelength is 1, the copied data shows 0. I have debugged my program and the data in the ring buffer is correct etc it shows the correct size of 1.

Anyone have any idea if my copy constructor is wrong or do i need an assignment operator overload ??

Thanks!

The code i used for insert/remove into ring buffer:

void insertq(struct queue *p, MyData v)
{
    int t;
    t = (p->rear+1)%MAX;
    if(t == p->front)
    {   }
    else
    {
            p->rear = t;        
            p->arr[p->rear] = v;
    }
}
MyData removeq(struct queue *p)
{
    MyData empty;   

    if(isempty(p))
    {               
        return empty;
    }
    else
    {       
        p->front = (p->front + 1)%MAX;
        empty = p->arr[p->front];
        return empty;
    }
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:55:19+00:00Added an answer on May 30, 2026 at 12:55 pm

    Thanks all for the advice. I have removed the copy constructor and assignment overload methods as suggested.

    The issue was with the circular buffer structure I used. I changed the circular buffer code to this example here:

    http://www.codeproject.com/Articles/43510/Lock-Free-Single-Producer-Single-Consumer-Circular

    and it worked. There seem to be no more errors. I had initially thought that the problem was due to the copy or assignment operator as the error was intermittent and so I did not check if it was the circular buffer that was causing the error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having this route: map.foo 'foo/*path', :controller => 'foo', :action => 'index' I have the
Having difficulty articulating this correlated subquery. I have two tables fictitious tables, foo and
Having the following code: int main(int argc, char* argv[]) { // program code std::cout
Having the following code: template<typename T, typename OutStream = std::ostream> struct print { OutStream
Having the following domain class: class Message{ } Want to get all messages with
Having the following code: #include <iostream> struct A { int x; A(){} ~A(){std::cout <<~A(<<x<<)\n;}
I have some code I that although it works, its making my content erratic.
Having problems with out of scope for NSDate in an iphone app. I have
Having the following classes (highly simplified): public class Child { public string Label; public
I'm having a very erratic problem with forms auth I'm hoping someone can shed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.