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

  • SEARCH
  • Home
  • 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 8975185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:48:52+00:00 2026-06-15T18:48:52+00:00

Okay, so I am trying to compile something right now and I am new

  • 0

Okay, so I am trying to compile something right now and I am new to C++ so maybe the code itself is causing the error however no red marks show up in the code itself that Eclipse is showing me.

Here is what the error says

c:\mingw\bin../lib/gcc/mingw32/4.6.2/include/c++/bits/move.h:128:7:
error: assignment of read-only reference ‘__a’

c:\mingw\bin../lib/gcc/mingw32/4.6.2/include/c++/bits/move.h:129:7:
error: assignment of read-only reference ‘__b’

Any ideas on what I need to do? on a Win7, using Eclipse Juno for C++ with MingwCC

Here is what I am compiling, the only new thing I added was this “swap” thing that someone told me to use for my permutation program.

UPDATED
Permutation.cc

 #include <iostream>   // for cout
#include <cstdio>     // for printf()
#include <sstream>    // for stringstream
#include <stdio.h>
#include <string.h>
#include "Permutation.h"
using namespace std;

Permutation::Permutation() {
    /* nothing needed in the constructor */
}

void Permutation::permute(string str) {

    int low = 0;
    int high = str.length();
        int j;
        if (low == high) {
            cout << str << endl;
        } else {
            for (j = low; j <= high; j++) {
            std::swap(str[low], str[j]);
            permute(str, low + 1, high);
            std::swap(str[low], str[j]);
        }
        }
    }


void Permutation::permute(string str, int low, int high) {
//  int j;
//  if (low == high) {
//      cout << str << endl;
//  } else {
//      for (j = low; j <= high; j++) {
//          std::swap(str[j + low], str[j + j]);
//          permute(str, low + 1, high);
//          std::swap(str[j + low], str[j + j]);
//      }
//  }
}

Permutation.h

#pragma once
#include <string>
using namespace std;
class Permutation {
    public:
        Permutation();

        void permute (string);
        void permute (string, int, int);
    private:
        /* attemp to solve this problem without adding 
         * any instance variables/data members, but
         * you may add private helper function members
         * as many as you need */
};

main.cc

#include "Permutation.h"

int main()
{
    Permutation p;


    p.permute ("Permute");
    p.permute ("--*--", 2, 3);
}
  • 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-06-15T18:48:53+00:00Added an answer on June 15, 2026 at 6:48 pm

    I rewrote the C code you linked to in C++:

    // this method should be private or protected because
    // str is passed by reference and will be modified !
    // if you prefer a free standing function, don't add the
    // declaration to the header, this for internal use only
    void do_permute(std::string& str, unsigned i, unsigned n) {
        // you COULD pass str by value here, which
        // would remove the need to backtrack.
        // however, it would create a new copy for every
        // iteration which is terrible for performance,
        // especially with long strings.
        if(i==n)
            std::cout << str << '\n';
        else
            for(unsigned j=i; j<=n; ++j) {
                std::swap(str[i],str[j]);
                do_permute(str,i+1,n);
                std::swap(str[i],str[j]); // backtrack (undo swap)
            }
    }
    
    // this is the public method;
    // pass string by value (copy), to allow do_permute()
    // to modify the string.
    void permute(std::string str, unsigned i=0, unsigned n=0) {
        if( n >= str.length() )
            return; // prevent out of bounds access
        // if n is 0 (default value) use the string length instead
        do_permute(str, i, n ? n : (str.length()-1) );
    }
    
    int main() {
        permute("BAR");
        permute("FO0BAR", 3);    // FOO***
        permute("FO0BAR", 0, 2); // ***BAR
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

okay, i'm trying to compile the fileshare example called 'pcp' using the following command
Currently I am trying to compile native code for Android. The code is from
I'm trying to install (and compile but the error is due to the same
Okay I'm trying to go for a more pythonic method of doing things. How
Okay I been trying to work this out but unable too. I have a
okay i have been trying to understand this for hours i am learning VB
Okay so I've been trying to position these 4 divs for about 6 hours
Okay so I'm trying to make a little gag program that will run away
Okay so what i am trying to achieve is use the youtube api to
OKay I don't use actionscript and trying to help my friend edit a flash

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.