| | |
Compile Error - Multi-file - Classes
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
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.
And this file:
When trying to compile the above I get an error reported in the second file at the first brace indicating
Both files are in the same directory. Can somebody point me in the right direction.
cpp Syntax (Toggle Plain Text)
/* 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
cpp Syntax (Toggle Plain Text)
/* 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; }
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.
Last edited by superjacent; Jan 27th, 2008 at 11:36 pm. Reason: Added extra error message
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.
•
•
•
•
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.
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 isC:/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
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.
And your program must have a main() function.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
•
•
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.
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.
![]() |
Other Threads in the C++ Forum
- Previous Thread: data c++
- Next Thread: how to make this program short
Views: 2556 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






