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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:08:16+00:00 2026-05-28T11:08:16+00:00

Compiling polygone.h and polygone.cc gives error: polygone.cc:5:19: error: expected constructor, destructor, or type conversion

  • 0

Compiling polygone.h and polygone.cc gives error:

polygone.cc:5:19: error: expected constructor, destructor, or type conversion before ‘(’ token

Code:

//polygone.h
# if !defined(__POLYGONE_H__)
# define __POLYGONE_H__

# include <iostream>

class Polygone {

    public:
        Polygone(){};
        Polygone(std::string fichier);

};

# endif

and

//polygone.cc
# include <iostream>
# include <fstream>
# include "polygone.h"

Polygone::Polygone(string nom)
{
    std::ifstream fichier (nom, ios::in);
    std::string line;

    if (fichier.is_open())
    {
        while ( fichier.good() )
        {
            getline (fichier, line);
            std::cout << line << std::endl;
        }
    }
    else
    {
        std::cerr << "Erreur a l'ouverture du fichier" << std::endl;
    }
}

//ifstream fich1 (argv[1], ios::in);

My guess is that the compiler is not recognising Polygone::Polygone(string nom) as a constructor, but, if this actually is the case, I have no idea why.

Any help?

  • 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-28T11:08:16+00:00Added an answer on May 28, 2026 at 11:08 am

    The first constructor in the header should not end with a semicolon. #include <string> is missing in the header. string is not qualified with std:: in the .cpp file. Those are all simple syntax errors. More importantly: you are not using references, when you should. Also the way you use the ifstream is broken. I suggest learning C++ before trying to use it.

    Let’s fix this up:

    //polygone.h
    # if !defined(__POLYGONE_H__)
    # define __POLYGONE_H__
    
    #include <iostream>
    #include <string>    
    
    class Polygone {
    public:
      // declarations have to end with a semicolon, definitions do not
      Polygone(){} // why would we needs this?
      Polygone(const std::string& fichier);
    };
    
    # endif
    

    and

    //polygone.cc
    // no need to include things twice
    #include "polygone.h"
    #include <fstream>
    
    
    Polygone::Polygone(const std::string& nom)
    {
      std::ifstream fichier (nom, ios::in);
    
    
      if (fichier.is_open())
      {
        // keep the scope as tiny as possible
        std::string line;
        // getline returns the stream and streams convert to booleans
        while ( std::getline(fichier, line) )
        {
          std::cout << line << std::endl;
        }
      }
      else
      {
        std::cerr << "Erreur a l'ouverture du fichier" << std::endl;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When compiling this code I get the following error : In function 'int main()':
While compiling some code I receive the following: error C2018: unknown character '0x40' I
After compiling my java code under Eclipse, I got the following error messages: SLF4J:
While compiling the c++ code using android NDK I am getting the following error:
Compiling this code snippet with gcc (4.5) and as many -Wall, -Wextra, -Wuninitialized type
When compiling the code below, I get the following error: PersonalInformation is not abstract
When compiling code with VC++, MSDN gives you the option between using the x86_amd64
When compiling my C++ .Net application I get 104 warnings of the type: Warning
When compiling the following code: void DoSomething(int Numbers[]) { int SomeArray[] = Numbers; }
I ran into an issue while compiling an openGl code. The thing is that

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.