Help Please! Error messages with classes.

I am writing a credit card simulator that uses classes. On my CreditCard.h file, I am getting error messages on the commented line below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#include <string>

using namespace System;
using namespace std;

class CreditCard 
{
public:
	CreditCard();
	CreditCard(int bc);
	double getCredLimit();
	double getBalDue();
	int getAccNum();
	double credAvailable();
	int incre_Credit();
	void trans1();
	int cdInc();
	bool addingChrg(double chrgAmt, const std::string& desc);
	~CreditCard();

private:
	int accNo;
	bool err;
	string mssg;
	double lim;
	double dueAmt;
	void wtStats();
	void logFl(string qu);
	string credName, credlastName;
	double bala = lim;            // this is the line I am getting 3 errors
	double payscale;
	double chrg;
};

The errors are

error C2327: 'CreditCard::lim' : is not a type name, static, or enumerator
error C2065: 'lim' : undeclared identifier
error C2864: 'CreditCard::bala' : only static const integral data members can be initialized within a class

What am I doing wrong?
assign that in the constructor of the class. You can't assign this way at this point. Also, lim has no value at this point in the code anyway, so it would be copying junk to junk .


think of it this way:
a class is a type. so double lim; inside your class DOES NOT EXIST yet. It only exists when you make an object of the class type: creditcard cc; //creates instance of the class, bringing cc.lim into existence.

Last edited on
I'm fairly new to C++, and my programming vocab is rusty, where is the constructor of the class located?
I'm fairly new to C++, and my programming vocab is rusty, where is the constructor of the class located?


Line 10 and 11 of the code you posted are both constructors.
Last edited on
To be more precise, lines 10 and 11 declare the constructors. The actual definitions of those constructors are, presumably, in the cpp file along with the rest of the method definitions.
Topic archived. No new replies allowed.