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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:22:12+00:00 2026-06-14T11:22:12+00:00

Why do the compiler complain redefiniton of ‘reader’ with a different type when I

  • 0

Why do the compiler complain redefiniton of 'reader' with a different type when I try to pass an fstream object from main() into another class´s constructor for it to be read? I am aware of this is maybe i dumb way of doing it, I should really just have a string as parameter asking for filename then pass that into the fstream that I allocate in the constructor of the class. But anyways I am wondering why this don´t work, the compiler warning is cryptic.

my main function:

fstream reader;
reader.open("read.txt");
Markov(reader);

Constructor in Markov.h class:

class Markov {
public:
/** Constructor */
    Markov(fstream inStream) {
    Map<string, Vector<string> > array0;

    char ch;
    while (inStream.good())
    {
        ch = inStream.get();
        cout << ch << endl;
    }
    cout << "End: " << ch;

    order0(array0);
}
  • 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-14T11:22:13+00:00Added an answer on June 14, 2026 at 11:22 am

    The line Markov(reader); is creating a variable called reader of type Markov. It is equivalent to the following: Markov reader;. Of course, since the compiler thinks you’re declaring another variable called reader, it throws up this error. To create an instance of Markov, do this:

    Markov m(reader);
    

    This is an ambiguity in the grammar of C++ that is always taken as a declaration of a variable, rather than the construction of a temporary. In fact, you can have as many parentheses as you like around the variable name in your declaration: Markov (((((reader))))).

    Markov(reader) is of course perfectly fine syntax for creating a temporary of type Markov, as long as it isn’t in a statement that could be parsed as a declaration. For example, if it’s in the middle of an expression, you’ll be okay. In the contrived expression something += Markov(reader) - 6, it can’t be interpreted as a declaration.

    Likewise, if there is more than one argument being passed to the constructor, Markov(reader, writer), or if the single argument is not an identifier, Markov("foo"), it is not ambiguous.

    If you’re using a C++11 compiler, you can indeed create a temporary (although I see no reason to do it) that takes a single argument identifier using the new initialization syntax:

    Markov{reader};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If the compiler is going to complain that a String object is not initialized
Why doesn't the compiler complain when I try to assign incorrect values to variable
Why does the C# compiler not even complain with a warning on this code?
This might be iPhone specific, I'm not sure. The compiler doesn't complain when building
g++ compiler complains about conversions between related types (from int to enum, from void*
This line of code causes compiler to complain and enter a debug mode NSLog(@Attacker
In the code below, why does the compiler not complain for mClass2? class CMyClass{
In other words, why does the compiler complain about things like this: class Integer
Can I define a macro like: #define ERROR_REPORT(LEVEL,SUB_LEVEL printf( Compiler complain this line expecting
Why does the compiler (g++) complain about this line of code? XalanNode *docElement =

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.