Dear members, please help with the following problem (it's on a beginner level).
I made a program that works, it uses a class. Then the book demonstrated how
to split the cpp file into one cpp and another one .h with the class, I managed to get it to work too. Then, the book demonstrated a technique of prototyping the class functions in a chocolate.h (chocolate is the class name) file, defining the class functions in a chocolate.cpp file. The class is used in the program hello.cpp
I tried to compile chocolate.cpp and then hello.cpp. chocolate.cpp compiled with a warning ("no start address") but hello.cpp would not compile. I use Digital Mars, here is the output from the compiler:
Error 42: Symbol Undefined ?getclassdata@chocolate@@QAE?AV?$basic_string@std@DV
?$char_traits@std@D@1@V?$allocator@std@D@1@@std@ (basic_string<>::d::DV?$char_tr
aits::std::D::chocolate syscall chocolate::getclassdata(allocator<>::d::D::choco
late ))
hello.obj(hello)
Error 42: Symbol Undefined ??0chocolate@@QAE@V?$basic_string@std@DV?$char_trait
s@std@D@1@V?$allocator@std@D@1@@std@ (syscall chocolate::chocolate(basic_string<
>::d::DV?$char_traits::std::D::basic_string<> ,allocator<>::d::D::basic_string<>
))
--- errorlevel 2
And now, my code.
hello.cpp:
#include <iostream>
#include <string>
using namespace std;
#include "chocolate.h"
I've never used Digital Mars, but how it usually works with IDEs is you create a "project", and add all of these files to the same project. You don't compile each file individually. Instead, you build the entire project.
What it sounds like is you're having hello.cpp and chocolate.cpp each in their own project. That won't work because that implies they each are their own program... when really, they must be part of the same program.
thanks disch. dm is actually not an IDE. I am very simple minded and the rough command-prompt interface of dm does it for me. (I actually had to play with the files included with DM in order to get it to run standard library stuff!)
do you see any problems with the codes themselves?
The book I am reading fails to explain how the 3 files are linked.
dm is actually not an IDE. I am very simple minded and the rough command-prompt interface of dm does it for me.
Screw that. Get an IDE. Manually compiling and linking your programs is a huge job, especially as your program grows to multiple files. Plus IDEs (and hell, even makefiles) let you shorten the compiling process by only recompiling files that have changed since the last build. When you have 20+ source files (not atypical in a moderate sized program), this makes a big difference.
Don't be a masochist. Don't make the building process difficult just because you want to be a minimalist. There's nothing wrong with using an IDE.
do you see any problems with the codes themselves?
No. Your code builds without errors on my machine.