Solved

Really really simple question about member functions in classes

Posted on 2007-11-26
2
187 Views
Last Modified: 2013-12-14
I mean really really simple.

All i want to do is make a class (in Visual C++ 2008) A  that has two int members b and c, and a function d  that adds them together. What i wrote is this:

-------------------A.h--------------------------
#ifndef A_H
#define A_H
#pragma once

class A
{
public:
      int b;
      int c;
      int d();
};
#endif
------------------------------------------------

-----------------A.cpp-------------------------
#include "A.h"

int d()
{
      int r = b + c;
      return r;
}
---------------------------------------------------

With this it tells me that in A.h, b and c are undeclared identifiers.
With A::b and A::c in A.h instead of just b and c it says "error C2597: illegal reference to non-static member 'A::b'" and i don't want them to be static members.

Anyone tell me what the correct method of doing this is?

Thanks a lot for your help.
James

0
Comment
Question by:jsab500
[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
  • 2
2 Comments
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 200 total points
ID: 20352212

Hi James.

easy fix:



int <classname>:: d()
{
  int r = b + c;
  return r;
}



Good Luck,
kent
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 20352221
That translates to:

int A::d()
{

}



Good Luck,
Kent
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dynamically allocate memory 9 70
How to convert MFC APP to Win32 APP. 19 112
C++ question 3 74
need help ...get stuck at middle of coding ...need to submit by Sunday C++ 1 44
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

726 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