|
From: disinfo on 8 Apr 2008 07:03 Hello I ve this two file: Conversion.h, conversion.cpp Code conversion.h: using namespace std; class Conversion { public: Conversion(); }; Code Conversion.cpp #include <iostream.h> #include "Conversion.h" using namespace std; Conversion() { cout << "test"; } with g++ C.* I recive the following error: Conversion.cpp:4: error: expected unqualified-id before ')' token I really don't understand where is my mistake. Any help will be very appreciate :) Thanks Disinfo
From: osmium on 8 Apr 2008 09:16 "disinfo" wrote: > I ve this two file: > > Conversion.h, conversion.cpp > > Code conversion.h: > > using namespace std; > class Conversion > { > public: > Conversion(); > }; > > Code Conversion.cpp > > #include <iostream.h> > #include "Conversion.h" > using namespace std; > > Conversion() You have to tell the compiler what class this function belongs to. Change to Conversion::Conversion() > { > cout << "test"; > } > > with g++ C.* I recive the following error: > Conversion.cpp:4: error: expected unqualified-id before ')' token > > I really don't understand where is my mistake. > Any help will be very appreciate :) > > Thanks > > Disinfo
From: disinfo on 8 Apr 2008 10:43 Il Tue, 08 Apr 2008 06:16:08 -0700, osmium ha scritto: >You have to tell the compiler what class this function belongs to. >Change >to > Conversion::Conversion() Thank you, now is working!
From: Ulrich Eckhardt on 8 Apr 2008 14:51 disinfo wrote: > Code conversion.h: > > using namespace std; Ahem, you haven't included any header that uses anything from namespace std, so what is this doing there? > #include <iostream.h> If you are learning from a book or any kind of tutorial, you should definitely dump that book, because it is trying to teach you code in a dialect that predates the C++ standard, which is almost ten years old. In other words, the tutorial is for sure not up to date. The standard-conform equivalent to the above is #include <iostream> > with g++ C.* I recive the following error: _ALWAYS_ turn on warnings and always make sure you understand them before you ignore them. For GCC that is with '-Wall'. Uli
|
Pages: 1 Prev: 全香港最濺IT Manager http://geocities.com/it_super_manager/ Next: [C++] Simple Coding Challenges |