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

  • Home
  • SEARCH
  • 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 8019783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:29:43+00:00 2026-06-04T21:29:43+00:00

I’m a C# programmer trying to muddle through C++ to create a Windows Forms

  • 0

I’m a C# programmer trying to muddle through C++ to create a Windows Forms Application.
I have a Windows Form that makes use of a user-created class. Basically I’m trying to use a constructor that takes parameters, but my form won’t let me initialize the object with parameter. Here’s the code, hopefully somebody can explain the problem to me because I’m completely baffled…

Here’s my header file: BankAcct.h

public ref class BankAcct
{
    private:
        int money;

    public:
        BankAcct();
        BankAcct(int);
        void Deposit(int);
        void GetBalance(int&);
};

And my definition file: BankAcct.cpp

#include "StdAfx.h"
#include "BankAcct.h"

BankAcct::BankAcct()
{
    money = 0;  
}
BankAcct::BankAcct(int startAmt)
{
    money = startAmt;
}
void BankAcct::Deposit(int depAmt)
{
    money += depAmt;
}
void BankAcct::GetBalance(int& balance)
{
    balance = money;
}

And finally my main form. Won’t copy the whole thing, of course, but I’m trying to declare the new bank account object, and start it with a balance of say $50.

private:
    BankAcct myAccount(50);    //does not work!  WHY??

//private:
  //BankAcct myAccount;    //works

then in the form constructor my code is this:

public:
    frmBank(void)
    {
        InitializeComponent();
        int bal;
        myAccount.GetBalance(bal);
        lblBankBalance->Text += Convert::ToString(bal);
    }

I’ve included the BankAcct.h file at the top of my frmBank.h, what else am I doing wrong here? It works great if I use the default constructor (the one that starts the bank balance at zero). I get the following error messages:

error C2059: syntax error: ‘constant’

and

error C2228: left of ‘.GetBalance’ must have class/struct/union

Thank you for any and all help on this one!!

  • 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-04T21:29:45+00:00Added an answer on June 4, 2026 at 9:29 pm

    C#-style initialization does not work in C++. You need to put initializers in the initialization section of your constructor (i.e. between : and the opening brace { of the constructor:

    public:
        MyForm() : myAccount(50) {
            // Your constructor
        }
    private:
        BankAcct myAccount;
    

    The way you have it now, myAccount is not defined as BankAcct, so calls of GetBalance do not compile either.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.