0

Hope someone can help. I'm self-studying from C++ Primer Plus, 5th Edition. I'm having trouble working out why the following two files will not compile. I'm using Dev-C++, under Windows Vista.

/*
  Name: bankaccount.h
  Copyright: 
  Author: Steven Taylor
  Date: 28/01/08 14:04
  Description: C++ Primer Plus, Chapter 10, Programming Exercise. #1. Page 496
*/
#ifndef BANKACCOUNT_H_
#define BANKACCOUNT_H_
class BankAccount
{
    private:
        char name[40];
        char acctnum[25];
        double balance;
    public:
        BankAccount(const char *client, const char *num, double bal = 0.0);
        void deposit(double cash);
        void withdraw(double cash);
        void show() const;
}
#endif

And this file:

/*
  Name: bankaccount.cpp
  Copyright: 
  Author: Steven Taylor
  Date: 28/01/08 14:03
  Description: BankAccount class methods. C++ Primer Plus, Chap 10, page 496
*/
#include <iostream>
#include <cstring>
#include "bankaccount.h"

BankAccount::BankAccount(const char *client, const char *num, double bal)
{           // error reported here - cannot 
    strncpy(name,client,39);
    name[39] = '\0';
    strncpy(acctnum, num,24);
    acctnum[25] = '\0';
    balance = bal;
}

When trying to compile the above I get an error reported in the second file at the first brace indicating 13 D:\Users\Steve\Documents\LearningCpp\LearningCppPrimer\Chapter-10\PE-01\bankaccount.cpp new types may not be defined in a return type Very next error message is 13 return type specification for constructor invalid Both files are in the same directory. Can somebody point me in the right direction.

2
Contributors
5
Replies
7
Views
9 Years
Discussion Span
Last Post by superjacent
0

Further, when I combine these two files into one file, for ease of compilation, I get the same compiler error message. So I suppose it's not related to a multiple file thing.

0

I think the problem is line 21 of the header file -- you have to have a semicolon at the end of the class. Put a semicolon after that closing brace.

0

I think the problem is line 21 of the header file -- you have to have a semicolon at the end of the class. Put a semicolon after that closing brace.

Thank you, how did I not see that.

I'm now getting another compiler error indicating this [Linker error] undefined reference to `WinMain@16' .

From another editor, Programmers Notepad, where all the above is just a single file I get the same error message, though with a little more detail, I assuming it's the same error > "C:\Dev-Cpp\bin\g++.exe" singlefile.cpp -o singlefile.exe and next line is

C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to `WinMain@16'
collect2: ld returned 1 exit status

I'm at a loss interpreting this.

0

You apparently created a Windows application, not a Console application. The easiest correction is to start a new console project then copy what you have done into it.

And your program must have a main() function.

0

You apparently created a Windows application, not a Console application. The easiest correction is to start a new console project then copy what you have done into it.

And your program must have a main() function.

Thank you once again, I quickly added a blank int main() function and it compiled without error. I shouldn't forget this gotcha in future.

ps. I probably should have created a new thread for my second question as the first was well and truly solved. Anyway, I'll mark this thread as solved.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.