Hello there, I am new to using classes, and have been having so many problems. I don't want to go to my teacher if I don't have to, because it is always my luck that it is something easy that I just overlooked somehow. I have been working on this for 3 days and I can't get it to read from a file.
Here is my header file:
Here is the cpp file attached to the header file:
The errors that I am receiving are attached to that cpp file and the error codes are:
And finally here is my main.cpp file:
I am sure the errors are connected to the array but I am not sure since I haven't worked with a class before. I have been googling and reading the book but I can't figure it out. Thanks for any help.
The error has nothing to do with it being a class or not...
You are passing it as a reference(&), which implies a single object. You should be passing it as a pointer(*) which implies one or more objects in a row -- i.e. a pointer to an object, or a pointer to several objects. You don't need to take the address of the array itself -- the array itself already is an address, which the [] operator converts into a direct access..
---------- Post updated at 04:38 PM ---------- Previous update was at 04:15 PM ----------
Why have you declared all your members as pointers, by the way? You'll have to allocate them or make them point to something before you can use them -- being pointers, they are useless until you give them something to point to. If you just want them to hold one value per object, remove the * and just let them be floats.
Last edited by Corona688; 02-05-2012 at 06:36 PM..
Can anyone tell me if this is correct when creating classes in Java?
public abstract class Animal
{
public class Point
{
public int x,y;
}
public class Animal
{
protected Point loc;
protected String name;
protected Random rng;
String... (3 Replies)
Hello All,
I am a learner in C++. I was testing my inheritance knowledge with following piece of code.
#include <iostream>
using namespace std;
class base
{
public :
void display()
{
cout << "In base display()" << endl;
}
void display(int k)
{... (2 Replies)
I have the two class definition as follows.
class A { public: int a; };
class B : virtual public A{ };
The size of class A is shown as 4, and size of class B is shown as 16. Why is this effect ?. (2 Replies)
Hi all!
I am trying to register a device in an existing device class, but I am
having trouble getting the pointer to an existing class.
I can create a class in a module, get the pointer to it and then use
it to register the device with:
*cl = class_create(THIS_MODULE, className);... (0 Replies)
Hi,
I believe the next code is wrong:
class Egg {
Egg e;
int i;
Egg(int ii=0) : i(ii) {}
};
because you would end up with an endless definition (memory allocation) of Egg objects, thus int i.
Ok, so God Eckel proposes for a singleton:
class Egg {
static Egg e;
int... (5 Replies)
I have a file Map.hh shown below. I want to put the two classes Phase and Map in two different files Phase.hh and Map.hh. I have forward declaration before the Map class. How can I tackle this situation?
//////////////////////////////////////////////////////////////////////////
#ifndef... (3 Replies)
Hi, i have a question about C++. Is it possible to declare a class with a member ot the same class? For example, a linked list or i want to convert this C code to C++ class (Elemento)
typedef struct elemento
{
char name;
char value;
List<struct elemento> ltElementos;
... (7 Replies)
I was wondering if I could put the section at the beginning rather than at the end before the definition of the class.
const REAL ModMisfit::DefMinDT = 0.01;
const REAL ModMisfit::DefSigma0 = 0.01;
const double ModMisfit::DefDAngSh = 2;
const REAL ModMisfit::DefKBeta = 5;... (2 Replies)
im just trying to have some fun and kill some time writing a c++ program that has a person type in a car make and model then gives them a year and a price. or something like that. i always have problems getting it goin but once the ball is rolling im usually pretty good. anyone wanna help me out? ... (1 Reply)
Hi,
I've tried to use classes in my program, but the compiler simply gives an error on the word class . Am I the only one with this problem ? I have no idea how to use classes in c in linux environment(suse). If you've got any idea what should I do I would be very thankful.
Thanks to ya all !... (4 Replies)