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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:26:39+00:00 2026-06-01T20:26:39+00:00

Help! I’m new to C++… how can I fix this header file? #pragma once

  • 0

Help!
I’m new to C++…
how can I fix this header file?

#pragma once
class MyCls2
{
private:
    int _i, _j;
public:
    MyCls2(int i, int j) : _i(i), 
                            _j(j)
    MyCls2(); // error: expected a '{'
    ~MyCls2(void);
};

This is the error in MS VC 2010:

error: expected a ‘{‘


Thanks for the help, I got what I want now:

.h:

#pragma once
class MyCls2
{
private:
    int _i, _j;
public:
    MyCls2(int i, int j) ;
    MyCls2();
    ~MyCls2(void);
};

.cpp:

#include "StdAfx.h"
#include "MyCls2.h"


MyCls2::MyCls2()
{
}

MyCls2::MyCls2(int i, int j) : _i(i), 
    _j(j)
{
}
MyCls2::~MyCls2(void)
{
}
  • 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-01T20:26:40+00:00Added an answer on June 1, 2026 at 8:26 pm

    You’re missing the function body in your definition of the MyCls2 constructor that takes two ints.

    MyCls2(int i, int j) : _i(i), 
                            _j(j) {}
    

    Think of the initializer list as being part of the constructor itself (its definition, not its declaration). You can’t have part of a function’s definition somewhere, and another part elsewhere.

    If you want the initializer list in the header, you need the rest of that definition (the constructor body) in the header too, as above.
    If you don’t want the definition in the header, don’t put the initializer list in the header, put it in the implementation file.

    //header
      MyCls2(int i, int j);
    
    // implementation
    
    MyCls2::MyCls2(int i, int j) : _i(i), _j(j)
    {
       // constructor body
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Help me with this part of code: class Ooo attr_accessor :class_array end def func(ctx)
help fix this error Fatal error: Uncaught exception 'Exception' with message 'DateTime::_ construct() [datetime.--construct]:
Help me settle an argument here. Is this: SqlCommand cmd = new SqlCommand( sql
Help, I'm deperate..i can't continue my app because of this: I have setup one
Help me to implement an event, which handler can cancel it. public class BuildStartEventArgs
Help, I have this class var jMath = { pi2: Math.PI, foo: function() {
Help, if you can- The situation: http://foobar.com includes a remotely hosted javacript file (
Help, I'm trying to create a new post in my wordpress blog with custom
Help, I can't function without Resharper . All of a sudden my Alt +
Help, Im really sick of using this lots of nbsps in my results page.

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.