Solved

Really really simple question about member functions in classes

Posted on 2007-11-26
2
183 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
  • 2
2 Comments
 
LVL 45

Accepted Solution

by:
Kdo 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:Kdo
ID: 20352221
That translates to:

int A::d()
{

}



Good Luck,
Kent
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now