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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:00:03+00:00 2026-06-01T00:00:03+00:00

I’ve read all the suggestions I’ve found in the following links c++ typedef another

  • 0

I’ve read all the suggestions I’ve found in the following links

  1. c++ typedef another class's enum?
  2. http://forums.devarticles.com/c-c-help-52/how-to-use-enum-when-it-is-in-another-class-17773.html
  3. http://forums.codeguru.com/showthread.php?t=435215
  4. How do I use the Enum value from a class in another part of code?

but still wasn’t able to find a solution to my problem:

I need to construct an object of class A (whose constructor expects as an input
parameter an enumerative type of that class) from inside a function of an object of class B

Here are the code snippets:

File A.h:

Class A{
    public:
       enum FileType{TEXT, BIN};

       /*! This constructor initializes the data from a given file
        *  (binary, text, image). 
        */
       A(const std::string& filename, FileType type);

}

File A.cpp:

A::A(const std::string& filename, FileType type){
 ...
}

File B.h:

Class B{

    private:
       A objectOfClassA;

    public:
       enum FileType{TEXT = A::FileType::TEXT, BIN = A::FileType::BIN}; //<----THIS IS NOT WORKING!           
       foo_func(const std::string& filename, FileType type);

}

File B.cpp:

void B::foo_func(const std::string& filename, FileType type){

    this->objectOfClassA(filename, type); //should construct an object of class A
    ... //do stuff with objectOfClassA
}

File main.cpp:

int main(int argc, char** argv) {

    B objectOfClassB;
    objectOfClassB.foo_func("file_path", foo_func.TEXT);

}

By trying to run main program I get this error from compiler in the B.cpp file at line of function foo_func:

no match for call to ‘(A)
(std::basic_string, B::FileType&)’

which means that I’m not using the correct enum type to call A class constructor, but how can I fix this?

What am I doing wrong?

  • 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-01T00:00:05+00:00Added an answer on June 1, 2026 at 12:00 am

    B::FileType and A::FileType are different types. You need to typedef A::FileType FileType inside B to alias the types correctly so they are interchangeable. Otherwise B::FileType is an enum which is structurally the same as A::FileType, but unrelated in the type system. This answers your primary question.

    Fixing this still won’t permit your code to compile, however, and this is not what the error is complaining about.

    objectOfClassA is already constructed inside foo_func. Calling this->objectOfClassA(filename, type) is an attempt to use the overloaded () operator on the object; this operator does not exist so the code cannot compile. You can only construct objectOfClassA via B’s constructor using initializer notation, e.g.

    B::B(const std::string& filename, FileType type) : objectOfClassA(filename, type)
    {
      ...
    }
    

    Then in main you would do this:

    B objectOfClassB("file_path", B::TEXT);
    

    Step through in the debugger to see the control flow.

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

Sidebar

Related Questions

I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.