?
Solved

class error

Posted on 1998-02-10
8
Medium Priority
?
180 Views
Last Modified: 2010-04-10
I'm venturing forth into VC5 and C++. I declared a class in a header file but it keeps coming back with the error:
     'class' is followed by 'CRational' (missing ','?)

It's just a textbook class declaration so I don't know why VC5 sees the " class CRational" as two identifiers. Especially when class is a blue keyword on the screen.
0
Comment
Question by:dpms
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1181715
Post your code so we can see the problem.

Is it possible that CRational is already defined as a class name?
0
 

Author Comment

by:dpms
ID: 1181716
That would be funny...
Here the code, it's just the class declaration.

#ifndef PROTOS_H
#define PROTOS_H


class CRational
{
public:
      CRational (int n = 1, int d = 2);
      void Add  (int num1, int denom1, int num2, int denom2);
      void Sub  (int num1, int denom1, int num2, int denom2);
      void Mult (int num1, int denom1, int num2, int denom2);
      void Div  (int num1, int denom1, int num2, int denom2);
      void Reduce_Form        (int a, int b);
      void Display_Fraction (int a, int b);
      void Display_As_Float (int a, int b);
private:
      int m_Numerator;
      int m_Denominator;
};

#endif
0
 
LVL 32

Expert Comment

by:jhance
ID: 1181717
There must be more to it than this.  What you have posted compiles fine:

C:\users\default>cl /c crational.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 11.00.7022 for 80x86
Copyright (C) Microsoft Corp 1984-1997. All rights reserved.

crational.cpp

C:\users\default>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dpms
ID: 1181718
Taking off the #if/defines's. I've tried compiling it as a .c file just above an empty main(). Still gives me the same thing, and that's really all there is to the code - so if it compiles for you... I don't see why it wouldn't compile for me. Wierd??
0
 
LVL 32

Expert Comment

by:jhance
ID: 1181719
Here's what I compiled:

//#ifndef PROTOS_H
//#define PROTOS_H


class CRational
{
public:
CRational (int n = 1, int d = 2);
void Add (int num1, int denom1, int num2, int denom2);
void Sub (int num1, int denom1, int num2, int denom2);
void Mult (int num1, int denom1, int num2, int denom2);
void Div (int num1, int denom1, int num2, int denom2);
void Reduce_Form (int a, int b);
void Display_Fraction (int a, int b);
void Display_As_Float (int a, int b);
private:
int m_Numerator;
int m_Denominator;
};

//#endif

void main()
{
}

And here's what I got:

C:\users\default>cl crational.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 11.00.7022 for 80x86
Copyright (C) Microsoft Corp 1984-1997. All rights reserved.

crational.cpp
Microsoft (R) 32-Bit Incremental Linker Version 5.10.7303
Copyright (C) Microsoft Corp 1992-1997. All rights reserved.

/out:crational.exe
crational.obj

C:\users\default>
0
 

Accepted Solution

by:
donleyp earned 200 total points
ID: 1181720
You are using a .c file extension instead of the .cpp file extension. Change the extension on your source file to .cpp and it should compile fine.
0
 

Author Comment

by:dpms
ID: 1181721
Your right. Just out of curiosity...why does it matter if it has an extension of .c or .cpp?
0
 

Expert Comment

by:donleyp
ID: 1181722
The compiler processes .c file as 'C' language by default so that existing code may be compiled without all the errors and warnings old 'C' code is prone to generate when comiled by a C++ compiler. It's basically a backward compatibility thing. One common misconception is that C is a subset of C++. This is true syntactically, but semantically it is not. Among other differences, C++ enforces much stricter typing.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question