473,748 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error: Class * has no member named *

30 New Member
Upon compiling my code for a fraction class, the error that i get is a good 50 or so repetitions of

error: Class "Fraction" has no member named "Numer"
and
error: Class "Fraction" has no member names "Denom"

I'm guessing it has something to do with the declaration of these private objects in the .h file, and it's use in the source code

here's a snippet of one of the functions
Expand|Select|Wrap|Line Numbers
  1. bool operator>=( const Fraction& One, const Fraction& Two )
  2. {
  3.     int a, b, c, d, e;
  4.  
  5.     a = One.Numer();
  6.     b = One.Denom();
  7.     c = Two.Numer();
  8.     d = Two.Denom();
  9.  
  10.     e = b;
  11.     a = a*d;
  12.     b = b*d;
  13.     c = c*e;
  14.     d = d*e;
  15.  
  16.     return( a >= c );
  17. }
  18.  
the private declaration is
Expand|Select|Wrap|Line Numbers
  1.   private:
  2.  
  3.     int Numer_;
  4.     int Denom_;
  5.  
and the boolean operation is as follows
Expand|Select|Wrap|Line Numbers
  1. bool operator>=( const Fraction& One, const Fraction& Two);
  2.  
I'm unsure on classes in c++, but this error seems to be the only one

If you need more of my code to find the error, let me know.

Thanks,
-Myxamatosis
Feb 28 '08 #1
6 30728
oler1s
671 Recognized Expert Contributor
Why are you so surprised? You create private variables for the class. Then you create a separate function, that tries to access those private variables. Perhaps your function shouldn't be external to the Fraction class...
Feb 28 '08 #2
Myxamatosis
30 New Member
the bool functions are in the class source code, and the private members are in the fraction.h file.

I guess I just don't understand what you're getting at...I thought when you did
#include "proj.fraction. h"

in the .cpp file, it grants you the access to the members
Feb 28 '08 #3
Laharl
849 Recognized Expert Contributor
If your .cpp file is called proj.fraction.c pp, you will have access to them, if the functions are declared as member functions for your fraction class. The linker handles all this for you, as long as you #include your .h file.

Expand|Select|Wrap|Line Numbers
  1. //foo.h
  2. class foo{
  3.   public bar;
  4.   private blah;
  5.   int getBlah();
  6. };
  7.  
  8. //foo.cpp
  9. #include "foo.h"
  10. int foo::getBlah(){
  11.   return blah;
  12. }
  13.  
Feb 28 '08 #4
oler1s
671 Recognized Expert Contributor
I won't directly feed you the answer, because I want you to reach it on your own, but I'll say the following. If it doesn't make sense, don't hesitate to ask me to clarify.

the bool functions are in the class source code
I would imagine so. Your intention is that the bool functions are part of the class, right? However, just putting a function in the same source file as the rest of the class source code doesn't mean they are actually part of the class. Think of it this way. I could take each function of the class, and have it in a different source file. That's perfectly fine. I need to explicitly mark a function as part of a class. Still not getting it?

Expand|Select|Wrap|Line Numbers
  1. class A
  2. {
  3.     int add(int a, int b);
  4. };
  5.  
  6. int add(int c, int d);
  7.  
  8. int A::add(int a, int b) { return a + b }
  9. int add(int c, int d) { return c + d }
  10.  
Same for operators... Look up operator overloading for classes explicitly though.

I thought when you did
#include "proj.fraction. h"

in the .cpp file, it grants you the access to the members
All an include statement does is a copy/paste. That's it. Why do you need to copy paste fraction.h into the source file? Because when the compiler sees your source file, it's going to be sitting around wondering what "Fraction" is. So you need to declare the existence of this class called Fraction, and describe what's in it. But that doesn't mean when Fraction is declared that suddenly all syntax rules go out the window.

Sure, fraction.h is included. But is the operator >= a part of the fraction class? Not the way you wrote it. Then, because the variables are private, they cannot be accessed.
Feb 28 '08 #5
Myxamatosis
30 New Member
I toyed around with it, and I've managed to rid myself of the operator errors.

However, when I changed my logic operators to accept one parameter ( I had an error saying it can accept only one or zero) it now tells me that

error: `bool operator!=(cons t Fraction&)' must take exactly two arguments

The source code for the operator goes like this
Expand|Select|Wrap|Line Numbers
  1. bool operator!=( const Fraction& One )
  2. {
  3.     Fraction temp;
  4.     int a, b, c, d, e;
  5.  
  6.     a = One.Numer_;
  7.     b = One.Denom_;
  8.     c = temp.Numer_;
  9.     d = temp.Denom_;
  10.  
  11.     e = b;
  12.     a = a*d;
  13.     b = b*d;
  14.     c = c*e;
  15.     d = d*e;
  16.  
  17.     return( a != c );
  18. }
  19.  
I originally had it accepting two Fraction& arguments, but that gave me an error too

I'm kinda lost on this one again, some direction would be great
Feb 29 '08 #6
Laharl
849 Recognized Expert Contributor
That has to be a class member function so that the "this" object can be the hidden first parameter, as it is with all class methods.. 'This' is a pointer to the object calling the method so that it can be set to the other Fraction object.

Expand|Select|Wrap|Line Numbers
  1. class Foo{
  2.  int bar;
  3.  bool operator<(const Foo& other); //This is effectively bool operator<(this, const Foo& other);
  4. }
  5.  
  6. bool Foo::operator<(const Foo& other){
  7.  //Implementation
  8. }
  9.  
Feb 29 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2496
by: Jian H. Li | last post by:
Hello, What's the essential differences between the two ways of "class::member" & "object.member"(or object_pointer->member)? class C{ public: void f() {} int i; };
1
725
by: zx.zhangxiong | last post by:
Dear all, I'm puzzled about the usage of class member function. Any help would be appreciated. class Account { ...
0
990
by: michael | last post by:
How can I reference an instance of a static class member accross all translation units? I don't want to pass a reference between dlls. Lib1.dll PROJECT 1 A.h class A { public:
7
4375
by: Uwe Grawert | last post by:
Hello, a C-function expects me to give a pointer to a function as parameter. i want to give this function a pointer to a member function of a class but the compiler gives me an error: void (MyClass::*)(void*, void*) can not be converted to void (*)(void*, void*) i declared the function as protected. Is it not possible to give
2
2174
by: Phil Davidson | last post by:
/* (Posted to microsoft.public.dotnet.languages.vc) In C++/CLI under Visual Studio 2005, creating an "enum class" member called "Equals" can cause compiler error C1060 (out of memory) and C1063 (internal error). See the following example program, a CLR console app. Of course the obvious workaround is to refrain from using "Equals". But does that really violate the specification of the language or the CLR? And can the compiler be...
3
1493
by: =?Utf-8?B?Y2FsZGVyYXJh?= | last post by:
Dear all, I have one question base on a choice of having a public interfcace access compare to public class member. IN other word let say that I have a public interface named ImyInterface with public function and property. Then I define a class which implements that interface.My class contains public fcunction which provide services.
8
7631
by: nishit.gupta | last post by:
I was having a problem with template class memer function definition , so i serched the net and find that template class member fuction definition should be in header file else compilation will be successful but not linking. Can somebody help me in telling the exact reason why compiler cannot find the reference of template class member function definition defined in cpp file?? following problem is not linking (undefined reference of...
3
1880
by: zaeminkr | last post by:
I have class member data which is a pointer to class member function. However, I'm fail to compile the code. What is the correct grammar to make a function call by using static member data which is a pointer to a member function? class Test {
2
326
by: R Samuel Klatchko | last post by:
Ron Eggler wrote: You can do this with a forwarding function that is a static member (you can also do it with a non-member function). Because signal does not give you a way to attach some caller defined data, you will also need a static member variable to hold a pointer to the instance of the class you want to use: foo.h: class foo
0
8995
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8252
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.