is not a member error when trying to init members in constructor

A

alacrite

This one is driving me nuts. I hope that it has just been a long day
and I am missing something stupid. Here is the .h and .cpp to the class
I am just starting:

//-----------------------------------------------------------------------------
//
// FILE: lg_data_table.h


#ifndef LG_DATA_TABLE_H_INCLUDED
#define LG_DATA_TABLE_H_INCLUDED 1


class lg_data_table : public data_table
{
public:
lg_data_table(xml_lst&);
~lg_data_table(){};
int get_current_row_num(){return row_nm_cnt;};
void incrmnt_row(){row_nm_cnt++;};
protected:
int row_nm_cnt;

};

#endif;



//-----------------------------------------------------------------------------
//
// FILE: lg_data_table.cpp

#include <baselib.h>
#include <lg_data_table.h>

lg_data_table::lg_data_table(xml_lst& xml_lst):row_nm_cnt(0)
{
//then i do stuff with xml_lst which is not important to this example
}

when I try to compile I get an error saying that "row_nm_cnt is not a
member of lg_data_table"

I have no idea what is going on. I haved tried adding other member
variables and the same things happens. Anyone have any ideas. I am lost
for now.
 
V

Victor Bazarov

This one is driving me nuts. I hope that it has just been a long day
and I am missing something stupid. Here is the .h and .cpp to the
class I am just starting:

//-----------------------------------------------------------------------------
//
// FILE: lg_data_table.h


#ifndef LG_DATA_TABLE_H_INCLUDED
#define LG_DATA_TABLE_H_INCLUDED 1


class lg_data_table : public data_table
{
public:
lg_data_table(xml_lst&);
~lg_data_table(){};
int get_current_row_num(){return row_nm_cnt;};
void incrmnt_row(){row_nm_cnt++;};
protected:
int row_nm_cnt;

};

#endif;



//-----------------------------------------------------------------------------
//
// FILE: lg_data_table.cpp

#include <baselib.h>
#include <lg_data_table.h>

lg_data_table::lg_data_table(xml_lst& xml_lst):row_nm_cnt(0)
{
//then i do stuff with xml_lst which is not important to this example
}

when I try to compile I get an error saying that "row_nm_cnt is not a
member of lg_data_table"

I have no idea what is going on. I haved tried adding other member
variables and the same things happens. Anyone have any ideas. I am
lost for now.

Check your spelling (in the real code).

Check that your 'baselib.h' doesn't have the same include guards as
your 'lg_data_table.h' header.

Check that 'lg_data_table' class is defined at the point where you try
to define its constructor. Try declaring a global object of that type.

V
 
B

BigBrian

This one is driving me nuts. I hope that it has just been a long day
and I am missing something stupid. Here is the .h and .cpp to the class
I am just starting:

//-----------------------------------------------------------------------------
//
// FILE: lg_data_table.h


#ifndef LG_DATA_TABLE_H_INCLUDED
#define LG_DATA_TABLE_H_INCLUDED 1


class lg_data_table : public data_table
{
public:
lg_data_table(xml_lst&);
~lg_data_table(){};
int get_current_row_num(){return row_nm_cnt;};
void incrmnt_row(){row_nm_cnt++;};
protected:
int row_nm_cnt;

};

#endif;



//-----------------------------------------------------------------------------
//
// FILE: lg_data_table.cpp

#include <baselib.h>
#include <lg_data_table.h>

lg_data_table::lg_data_table(xml_lst& xml_lst):row_nm_cnt(0)
{
//then i do stuff with xml_lst which is not important to this example
}

when I try to compile I get an error saying that "row_nm_cnt is not a
member of lg_data_table"

I have no idea what is going on. I haved tried adding other member
variables and the same things happens. Anyone have any ideas. I am lost
for now.

What is data_table, xml_lst?

After commenting out the stuff that you didn't include ( data_table,
xml_lst ), and including a main, it compiles for me. The problem must
be something you didn't include.

-Brian
 
V

Victor Bazarov

Victor said:
This one is driving me nuts. [...]
#include <baselib.h>
#include <lg_data_table.h>

lg_data_table::lg_data_table(xml_lst& xml_lst):row_nm_cnt(0)

Also, I just noticed this: it's a BAD IDEA(tm) to name your argument
the same as the type of that argument.

V
 
A

alacrite

Thank you for the help. I still have not solved it but I have a ugly
temp work around. The lg_data_table class is called in another class
and when I create the lg_data_table object in that class I use a setter
to set the value of currnt_row_nm. I tried calling the setter from the
constructor and it did not recognize the function just like it did not
recognize the variable. I have not idea what is going on with that I
included the .h in the .cpp file so the class should know about these
things.

also the xml_lst and data_table classes are custom classes that are in
the baselibs.h. O well will have to look at this one again later.

thanks again for the quick help
 
H

Howard

Thank you for the help. I still have not solved it but I have a ugly
temp work around. The lg_data_table class is called in another class
and when I create the lg_data_table object in that class I use a setter
to set the value of currnt_row_nm. I tried calling the setter from the
constructor and it did not recognize the function just like it did not
recognize the variable. I have not idea what is going on with that I
included the .h in the .cpp file so the class should know about these
things.

also the xml_lst and data_table classes are custom classes that are in
the baselibs.h. O well will have to look at this one again later.

thanks again for the quick help

This indicates to me that the header file is not seen correctly by the .cpp
file.

The first thing that catches my eye is that your last line is

#endif;

That should be just

#endif

If that's not the problem, then here are some other ideas...

Perhaps you've got a copy of the file lying around somewhere, and that old
copy is being seen. Or, perhaps you've got another class with the same name
somewhere.

Or, perhaps you just need to clean and rebuild the entire thing.
(Sometimes, in VC++ especially, changes in header files don't seem to be
seen by the implementation files unless you do a complete rebuild.)

Another thought is that there are errors in the header file, and it's not
getting compiled, so that when the implementation file tries to use the
class, it's not fully defined.

And sometimes, if you copied the source from somewhere else, the line
endings are not correct, and the file isn't being parsed correctly. I have
also seen problems in some compilers if the last line of a header file was a
comment.

-Howard
 
A

alacrite

Well I found the problem... there was a typo in the make and it was not
seeing the include.

I apologize for the wasted time. Thanks again to all those who helped.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top