|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I am learning C++ from the following C++ website, which has some very good small examples. For the second Fraction example, which has five files: Main.cpp Fraction.cpp Fraction.h msoftcon.cpp msoftcon.h ,,,,, A Fraction class that has the ability to add, subtract, multiply, divide and show various statistics of the fraction. http://www.cplusplus.com/src/ ,,,,,,,,,,,,, When I compile them, MSVC 6++ compiler says: error C2653: 'Fraction' : is not a class or namespace name if I put Fraction.h with the .cpp under Source Files category. If I put Fraction.h under Header Files category, the compiler cannod find the .h file. I have also tried Settings in the Project menu without success. I am new to MSVC and C++, could you me the settings? Thank you very much. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Dec 25, 10:15 pm, fl <rxjw...@gmail.com> wrote:
> Hi, > I am learning C++ from the following C++ website, which has some very > good small examples. For the second Fraction example, which has five > files: > > Main.cpp > Fraction.cpp > Fraction.h > msoftcon.cpp > msoftcon.h > ,,,,, > A Fraction class that has the ability to add, subtract, multiply, > divide and show various statistics of the fraction. > > http://www.cplusplus.com/src/ > ,,,,,,,,,,,,, > > When I compile them, MSVC 6++ compiler says: > > error C2653: 'Fraction' : is not a class or namespace name > if I put Fraction.h with the .cpp under Source Files category. > > If I put Fraction.h under Header Files category, the compiler cannod > find the .h file. I have also tried Settings in the Project menu > without success. I am new to MSVC and C++, could you me the > settings? Thank you very much. Did you #include "Fraction.h" in Main.cpp and Fraction.cpp? |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 25 déc, 23:12, johanatan <johana...@gmail.com> wrote:
> On Dec 25, 10:15 pm, fl <rxjw...@gmail.com> wrote: > > > > > > > Hi, > > I am learning C++ from the following C++ website, which has some very > > good small examples. For the second Fraction example, which has five > > files: > > > Main.cpp > > Fraction.cpp > > Fraction.h > > msoftcon.cpp > > msoftcon.h > > ,,,,, > > A Fraction class that has the ability to add, subtract, multiply, > > divide and show various statistics of the fraction. > > >http://www.cplusplus.com/src/ > > ,,,,,,,,,,,,, > > > When I compile them, MSVC 6++ compiler says: > > > error C2653: 'Fraction' : is not a class or namespace name > > if I put Fraction.h with the .cpp under Source Files category. > > > If I put Fraction.h under Header Files category, the compiler cannod > > find the .h file. I have also tried Settings in the Project menu > > without success. I am new to MSVC and C++, could you me the > > settings? Thank you very much. > > Did you #include "Fraction.h" in Main.cpp and Fraction.cpp?- Masquer le texte des messages précédents - > > - Afficher le texte des messages précédents - In Main.cpp, Fraction.h is included. At the end of Fraction.h, there is: ........... #include "Fraction.cpp" #endif ........... Fraction.cpp seems to be part of declaration of class Fraction function. I don't know how to solve this. Thanks. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
fl wrote:
> Hi, > I am learning C++ from the following C++ website, which has some very > good small examples. For the second Fraction example, which has five > files: > > Main.cpp > Fraction.cpp > Fraction.h > msoftcon.cpp > msoftcon.h > ,,,,, > A Fraction class that has the ability to add, subtract, multiply, > divide and show various statistics of the fraction. > > http://www.cplusplus.com/src/ > ,,,,,,,,,,,,, > > When I compile them, MSVC 6++ compiler says: > > error C2653: 'Fraction' : is not a class or namespace name > if I put Fraction.h with the .cpp under Source Files category. > > If I put Fraction.h under Header Files category, the compiler cannod > find the .h file. I have also tried Settings in the Project menu > without success. I am new to MSVC and C++, could you me the > settings? Thank you very much. You have to include the header in the source file. Your book should explain this. Brian |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On 25 déc, 23:23, "Default User" <defaultuse...@yahoo.com> wrote:
> fl wrote: > > Hi, > > I am learning C++ from the following C++ website, which has some very > > good small examples. For the second Fraction example, which has five > > files: > > > Main.cpp > > Fraction.cpp > > Fraction.h > > msoftcon.cpp > > msoftcon.h > > ,,,,, > > A Fraction class that has the ability to add, subtract, multiply, > > divide and show various statistics of the fraction. > > >http://www.cplusplus.com/src/ > > ,,,,,,,,,,,,, > > > When I compile them, MSVC 6++ compiler says: > > > error C2653: 'Fraction' : is not a class or namespace name > > if I put Fraction.h with the .cpp under Source Files category. > > > If I put Fraction.h under Header Files category, the compiler cannod > > find the .h file. I have also tried Settings in the Project menu > > without success. I am new to MSVC and C++, could you me the > > settings? Thank you very much. > > You have to include the header in the source file. Your book should > explain this. > > Brian- Masquer le texte des messages précédents - > > - Afficher le texte des messages précédents - The Fraction.h is included in the main.cpp, see below. // Allow the integer type to be changed on the fly #define BIGGEST_INT int #include <iostream.h> // Include C++ input/output functions #include <stdio.h> // Include C input/output functions #include <conio.h> // Include for pausing the program #include <stdlib.h> // Include C Library functions #include "Fraction.h" // Includes the Fraction Header File #include "msoftcon.h" // Allows more functionality to MVC++ console int main() { Fraction a; Fraction b; Fraction c; ----- Thanks. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
The example is broken, I am afraid you may have to spend some time
reading the code and debugging. It will be a good learning experience ![]() fl wrote: > Hi, > I am learning C++ from the following C++ website, which has some very > good small examples. For the second Fraction example, which has five > files: > > Main.cpp > Fraction.cpp > Fraction.h > msoftcon.cpp > msoftcon.h > ,,,,, > A Fraction class that has the ability to add, subtract, multiply, > divide and show various statistics of the fraction. > > http://www.cplusplus.com/src/ > ,,,,,,,,,,,,, > > When I compile them, MSVC 6++ compiler says: > > error C2653: 'Fraction' : is not a class or namespace name > if I put Fraction.h with the .cpp under Source Files category. > > If I put Fraction.h under Header Files category, the compiler cannod > find the .h file. I have also tried Settings in the Project menu > without success. I am new to MSVC and C++, could you me the > settings? Thank you very much. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On 2007-12-26 04:15, fl wrote:
> Hi, > I am learning C++ from the following C++ website, which has some very > good small examples. For the second Fraction example, which has five > files: A few tips if you want to learn C++: 1. While there are some websites out there which I would classify as "not bad" there are none that I would consider "good", and they tend to be very incomplete (not discussing important topics or only parts of them). There are a number of good books out there, and if you search the archives you can find a few that gets recommended often. 2. There are good compilers and there are bad compilers. MSVC++ 6 is one of the worst, it is simply too old (almost 10 years now) and does not support many features in C++. If you want to learn you have to get a newer one, there are a number of gcc bases you can download, and Microsoft's Visual C++ 2008 Express can also be downloaded for free. -- Erik Wikström |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
fl wrote:
> On 25 déc, 23:23, "Default User" <defaultuse...@yahoo.com> wrote: > > You have to include the header in the source file. Your book should > > explain this. > The Fraction.h is included in the main.cpp, see below. Post a complete, minimal program that demonstrates the problem. That means the header files as well as the source. See the newsgroup FAQ under "how to post". Brian |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
On 26 déc, 06:42, Erik Wikström <Erik-wikst...@telia.com> wrote:
> On 2007-12-26 04:15, fl wrote: > > > Hi, > > I am learning C++ from the following C++ website, which has some very > > good small examples. For the second Fraction example, which has five > > files: > > A few tips if you want to learn C++: > > 1. While there are some websites out there which I would classify as > "not bad" there are none that I would consider "good", and they tend to > be very incomplete (not discussing important topics or only parts of > them). There are a number of good books out there, and if you search the > archives you can find a few that gets recommended often. > > 2. There are good compilers and there are bad compilers. MSVC++ 6 is one > of the worst, it is simply too old (almost 10 years now) and does not > support many features in C++. If you want to learn you have to get a > newer one, there are a number of gcc bases you can download, and > Microsoft's Visual C++ 2008 Express can also be downloaded for free. > > -- > Erik Wikström Hi, Thank all of you very much. In fact, I am reading the cpp primer of lippman now. And I have one MS .net V7.1 enen though it is not a English version. I have downloaded the source code of that book. But I don't know the best way to use it, i.e. How to compile it as in the readme.txt file? It says: -------------------- To use make on a Windows operating system you invoke the command name "nmake": ## Windows machines > nmake # compiles all the programs > nmake clean # removes all the object files and stackdumps > nmake clobber # removes executable, object and stackdump files -------------------- My computer doesn't understand the nmake command. Could you tell me something about that? Thanks again. |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
On Dec 25, 11:23 pm, fl <rxjw...@gmail.com> wrote:
> On 25 déc, 23:12, johanatan <johana...@gmail.com> wrote: > > > > > On Dec 25, 10:15 pm, fl <rxjw...@gmail.com> wrote: > > > > Hi, > > > I am learning C++ from the following C++ website, which has some very > > > good small examples. For the second Fraction example, which has five > > > files: > > > > Main.cpp > > > Fraction.cpp > > > Fraction.h > > > msoftcon.cpp > > > msoftcon.h > > > ,,,,, > > > A Fraction class that has the ability to add, subtract, multiply, > > > divide and show various statistics of the fraction. > > > >http://www.cplusplus.com/src/ > > > ,,,,,,,,,,,,, > > > > When I compile them, MSVC 6++ compiler says: > > > > error C2653: 'Fraction' : is not a class or namespace name > > > if I put Fraction.h with the .cpp under Source Files category. > > > > If I put Fraction.h under Header Files category, the compiler cannod > > > find the .h file. I have also tried Settings in the Project menu > > > without success. I am new to MSVC and C++, could you me the > > > settings? Thank you very much. > > > Did you #include "Fraction.h" in Main.cpp and Fraction.cpp?- Masquer le texte des messages précédents - > > > - Afficher le texte des messages précédents - > > In Main.cpp, Fraction.h is included. > At the end of Fraction.h, there is: > ........... > #include "Fraction.cpp" > #endif > ........... > > Fraction.cpp seems to be part of declaration of class Fraction > function. I don't know how to solve this. Thanks. No need to #include the cpp. VC++ will compile the cpp if it is in your 'source files' section of Solution Explorer (i.e., has been added to the project). --Jonathan |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
On Dec 25, 7:15 pm, fl <rxjw...@gmail.com> wrote:
> Hi, > I am learning C++ from the following C++ website, which has some very > good small examples. For the second Fraction example, which has five > files: > > Main.cpp > Fraction.cpp > Fraction.h > msoftcon.cpp > msoftcon.h > ,,,,, > A Fraction class that has the ability to add, subtract, multiply, > divide and show various statistics of the fraction. > > http://www.cplusplus.com/src/ > ,,,,,,,,,,,,, > > When I compile them, MSVC 6++ compiler says: > > error C2653: 'Fraction' : is not a class or namespace name > if I put Fraction.h with the .cpp under Source Files category. > > If I put Fraction.h under Header Files category, the compiler cannod > find the .h file. I have also tried Settings in the Project menu > without success. I am new to MSVC and C++, could you me the > settings? Thank you very much. I don't have MSVC 6.0 installed now, but after view the source code (fraction2.zip ?), you can try this: -Open MSVC 6.0 and create new "Window Console" project (select empty project) -Copy all file in fraction2 to your new project's folder -In MSVC 6.0, in File view tab, chose add file in context menu to add all files (just copy before) If it does not compiled, let me know. |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
On 26 déc, 20:28, johanatan <johana...@gmail.com> wrote:
> On Dec 25, 11:23 pm, fl <rxjw...@gmail.com> wrote: > > > > > > > On 25 déc, 23:12, johanatan <johana...@gmail.com> wrote: > > > > On Dec 25, 10:15 pm, fl <rxjw...@gmail.com> wrote: > > > > > Hi, > > > > I am learning C++ from the following C++ website, which has some very > > > > good small examples. For the second Fraction example, which has five > > > > files: > > > > > Main.cpp > > > > Fraction.cpp > > > > Fraction.h > > > > msoftcon.cpp > > > > msoftcon.h > > > > ,,,,, > > > > A Fraction class that has the ability to add, subtract, multiply, > > > > divide and show various statistics of the fraction. > > > > >http://www.cplusplus.com/src/ > > > > ,,,,,,,,,,,,, > > > > > When I compile them, MSVC 6++ compiler says: > > > > > error C2653: 'Fraction' : is not a class or namespace name > > > > if I put Fraction.h with the .cpp under Source Files category. > > > > > If I put Fraction.h under Header Files category, the compiler cannod > > > > find the .h file. I have also tried Settings in the Project menu > > > > without success. I am new to MSVC and C++, could you me the > > > > settings? Thank you very much. > > > > Did you #include "Fraction.h" in Main.cpp and Fraction.cpp?- Masquer le texte des messages précédents - > > > > - Afficher le texte des messages précédents - > > > In Main.cpp, Fraction.h is included. > > At the end of Fraction.h, there is: > > ........... > > #include "Fraction.cpp" > > #endif > > ........... > > > Fraction.cpp seems to be part of declaration of class Fraction > > function. I don't know how to solve this. Thanks. > > No need to #include the cpp. VC++ will compile the cpp if it is in > your 'source files' section of Solution Explorer (i.e., has been added > to the project). > > --Jonathan- Masquer le texte des messages précédents - > > - Afficher le texte des messages précédents - Hi, Now I am trying on MSVC 7.1. I find it is really complicated! I don't know how to compile a simple .cpp file. I type namke in the bottom window, nothing happens. Could you tell me to compile the simplest win32 console example (which is from C++ primer book). Thank you very much. |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
On Dec 26, 5:55 pm, fl <rxjw...@gmail.com> wrote:
> > Hi, > Now I am trying on MSVC 7.1. I find it is really complicated! I don't > know how to compile a simple .cpp file. I type namke in the bottom > window, nothing happens. Could you tell me to compile the simplest > win32 console example (which is from C++ primer book). Thank you very > much. You can follow this (I don't have VS now): http://www.ucancode.net/Visual-Studi...P-Tutorial.htm Open MSVC -Create new project (File-New-Project) -Select Visual C++ Project, and select Win32 (not .NET, in figure 2) -In the right, select Window Console -Select simple hello world project. After explorer your new project, you will know where to paste your code. |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
On 26 déc, 21:06, quangtin3 <quangt...@gmail.com> wrote:
> On Dec 26, 5:55 pm, fl <rxjw...@gmail.com> wrote: > > > > > Hi, > > Now I am trying on MSVC 7.1. I find it is really complicated! I don't > > know how to compile a simple .cpp file. I type namke in the bottom > > window, nothing happens. Could you tell me to compile the simplest > > win32 console example (which is from C++ primer book). Thank you very > > much. > > You can follow this (I don't have VS now):http://www.ucancode.net/Visual-Studi...P-Tutorial.htm > Open MSVC > -Create new project (File-New-Project) > -Select Visual C++ Project, and select Win32 (not .NET, in figure 2) > -In the right, select Window Console > -Select simple hello world project. After explorer your new project, > you will know where to paste your code. Thank you very much. It can run now. The only problem is that it cannot run by Ctrl+F5 (with no debug mode running). The dialog box says that: It cannot start the program ......\...\xx.exe. The path cannot be found. In fact, the application xx.exe is right there. And I can exec it directly in a command window. Where to config that? Thanks again. |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
Erik Wikström wrote: > 2. There are good compilers and there are bad compilers. MSVC++ 6 is one > of the worst, it is simply too old (almost 10 years now) and does not > support many features in C++. If you want to learn you have to get a > newer one, there are a number of gcc bases you can download, and > Microsoft's Visual C++ 2008 Express can also be downloaded for free. > > -- > Erik Wikström I am learning C++ from books that were written around the time that MSVC 6 was released. For example, Stroustrup's C++ Programming language 3rd edition. MSVC6 library seems to be complete (or complete as far as Stroustrup's book is concerned.) Bjarne Stroustrup in a recent video was talking about the direction of C++. He was saying MS compilers are not too bad at all. What feature sets are missing from MSVC6 that make it such a bad compiler? |
|
|
|
#16 |
|
Messages: n/a
Hébergeur: |
On 26 déc, 12:53, "Default User" <defaultuse...@yahoo.com> wrote:
> fl wrote: > > On 25 déc, 23:23, "Default User" <defaultuse...@yahoo.com> wrote: > > > You have to include the header in the source file. Your book should > > > explain this. > > The Fraction.h is included in the main.cpp, see below. > > Post a complete, minimal program that demonstrates the problem. That > means the header files as well as the source. See the newsgroup FAQ > under "how to post". > > Brian Thanks. The original files (Fraction.cpp and Fraction.h) have to be combined together, I find. Thank you very much. |
|
|
|
#17 |
|
Messages: n/a
Hébergeur: |
On 2007-12-27 01:26, fl wrote:
> On 26 déc, 06:42, Erik Wikström <Erik-wikst...@telia.com> wrote: >> On 2007-12-26 04:15, fl wrote: >> >> > Hi, >> > I am learning C++ from the following C++ website, which has some very >> > good small examples. For the second Fraction example, which has five >> > files: >> >> A few tips if you want to learn C++: >> >> 1. While there are some websites out there which I would classify as >> "not bad" there are none that I would consider "good", and they tend to >> be very incomplete (not discussing important topics or only parts of >> them). There are a number of good books out there, and if you search the >> archives you can find a few that gets recommended often. >> >> 2. There are good compilers and there are bad compilers. MSVC++ 6 is one >> of the worst, it is simply too old (almost 10 years now) and does not >> support many features in C++. If you want to learn you have to get a >> newer one, there are a number of gcc bases you can download, and >> Microsoft's Visual C++ 2008 Express can also be downloaded for free. >> >> -- >> Erik Wikström > > Hi, > Thank all of you very much. In fact, I am reading the cpp primer of > lippman now. And I have one MS .net V7.1 enen though it is not a > English version. I have downloaded the source code of that book. But I > don't know the best way to use it, i.e. How to compile it as in the > readme.txt file? It says: > > -------------------- > To use make on a Windows operating system you invoke the command > name "nmake": > > ## Windows machines > > nmake # compiles all the programs > > nmake clean # removes all the object files and stackdumps > > nmake clobber # removes executable, object and stackdump > files > -------------------- > My computer doesn't understand the nmake command. Could you tell me > something about that? Thanks again. For with a specific compiler you should ask in a group discussing your compiler. Check out the groups in the microsoft.public.* hierarchy. If you have installed VS7.1 correctly you should have something called Visual Studio 7.1 Command Prompt somewhere on your start-menu, start that and then navigate the where you have your code and run nmake. -- Erik Wikström |
|
|
|
#18 |
|
Messages: n/a
Hébergeur: |
On 2007-12-27 04:21, nullius.filius@gmail.com wrote:
> > Erik Wikström wrote: > >> 2. There are good compilers and there are bad compilers. MSVC++ 6 is one >> of the worst, it is simply too old (almost 10 years now) and does not >> support many features in C++. If you want to learn you have to get a >> newer one, there are a number of gcc bases you can download, and >> Microsoft's Visual C++ 2008 Express can also be downloaded for free. >> >> -- >> Erik Wikström > > I am learning C++ from books that were written around the time that > MSVC 6 was released. For example, Stroustrup's C++ Programming > language 3rd edition. MSVC6 library seems to be complete (or > complete as far as Stroustrup's book is concerned.) While it might look complete I am quite sure it is not. > Bjarne Stroustrup in a recent video was talking about the direction > of C++. He was saying MS compilers are not too bad at all. He was talking about recent versions, the 2005 (and 2008) versions are among the best available, comparable to gcc (but not as good as Comeau). > What feature sets are missing from MSVC6 that make it such > a bad compiler? I seem to recall that the support for templates is not what it should be (which affects the library) and I am sure that there are other things that could be better. -- Erik Wikström |
|
![]() |
| Outils de la discussion | |
|
|