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 7650897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:22:13+00:00 2026-05-31T11:22:13+00:00

The error: g++ -Wall -Wextra -ansi -pedantic Testr.cc classE.cc classC.cc classE.cc:46:14: error: expected unqualified-id

  • 0

The error:

g++ -Wall -Wextra -ansi -pedantic Testr.cc classE.cc classC.cc
classE.cc:46:14: error: expected unqualified-id before '&'token
classC.cc:46:14: error: expected unqualified-id before '&'token

The line the compiler is referring to:

classE classE::&operator%(classB &rhs){

The compiler is talking about the ‘&’ in the ‘classE::&operator%’ expression; I’d just as soon delete the ampersand, but the assignment (yay arbitrary homework guidelines) requires it. I’m not even sure what the ampersand is supposed to do. Similar operator overloading methods use the same outline with no problem, and I have come up empty-handed through google and textbooks.

Specifying the derived class (classB.h is pure virtual) in the arguments doesn’t clear these errors, either.

Because other similarly-defined operators work with no issue, I believe the problem is in the implementation. The basic idea is to take two classB-derived objects (classC or classE), and interleave the string variable each object contains with the other, returning a lhs-type object containing the interwoven string. The classE implementation is effectively exactly like the classC implementation:

classC classC::&operator%(classB &rhs){ //Interleave two classB-derived objects, return object of lhs-type
  string temp = rhs.str(), temp2 = restore(), result = "";
  int a = temp.size(), b = temp2.size(), max;
    if (temp2.size() > temp.size()){
      max = temp2;
    }
    else{
      max = temp;
    }
    for (int i = 0; i < max; i++){
      if (i < a){
        result += temp2[i];
      }
      if (i < b){
    result += temp[i];
  }
}
return classC(result);
}

Sorry, I’m brand new here; I have no idea how to add line numbers to the code blocks =-\

Thanks for reading and considering my problem. =-)

EDIT: I was afraid it would be an embarrassingly stupid mistake; changing the line to
classE& classE::operator%(classB &rhs){
has opened up the floodgates for tons of new errors. Heh, just when I thought I was getting the hang of C++. Thanks a bunch, guys. I hope all of my future questions are as simple.

  • 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-31T11:22:14+00:00Added an answer on May 31, 2026 at 11:22 am
    classE classE::&operator%(classB &rhs)   
    

    Is not syntactically valid.


    If you are overloading the % operator all you need is:

    classE classE::operator%(classB &rhs)  
    

    If your intention is to return a reference, you need:

        classE& classE::operator%(classB &rhs) 
          ^       ^   ^    ^    ^    ^
          |       |   |    |    |    |
          |       |   |    |    |    |
      return type |   |  keyword| function arguments
                  |   |         |
           class name |     operator being overloaded 
                      |
                  scope resolution operator
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I compile function with gcc -o dene -Wall -ansi -pedantic-errors dene.c ,gcc emits
Error display as Incorrect syntax near '@Cmp_DocPath', if i use comment Line code I
Banging my head off the wall due to this. I'm getting the error at
I've got the following problem: cc -g -O2 -Wall -Wextra -Isrc -rdynamic -DNDEBUG build/liblcthw.a
PROJ = . SRC_ROOT = . FLAGS = -g -Wall -Wextra INC = -I$(PROJ)
I’m using g++ with warning level -Wall -Wextra and treating warnings as errors (
With GCC, when the -Wall -Wextra flags are enabled, one has the option of
I have this SConstruct file: env=Environment() env.Append(CCFLAGS = ['-std=c99', '-Wall', '-Wextra', '-g']) print env[CCFLAGS]
Naturally, this won't compile: int &z = 3; // error: invalid initialization of non-const
I'm using gcc -O -Wall -Wextra to try to help students find faults in

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.