C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 17th, 2007, 12:10 AM
mantai007 mantai007 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 290 mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 3 h 48 m 33 sec
Reputation Power: 11
Cannot access struct in h file

I created a node class and list class and declared the struct in the private of BookNode.. everytime i compile it says name undeclared..
i have declared a pointer to that class to access it and getter/setter methods too. but the function cant see the struct itself

Code:
BookNode.h

#include <stdlib.h>
#include <stdio.h>
using namespace std;

#ifndef BOOKNODE_H
#define BOOKNODE_H

class BookNode
{
private:

   struct Anode
   {
      String name;
      Anode *next;
      Anode()
      {
         next = NULL;
         name = NULL;
      }
   };

typedef Anode* NodePtr;

public:
   BookNode *bn;
   NodePtr aptr;
 
   BookNode();
   void setBookname(String name);
   String getName();
   NodePtr getNext();
}

#endif //BOOKNODE_H
--------------------------------------
BookNode.cpp

#include "BookNode.h"
#include "BookList.h"

BookNode::BookNode()
{
   bn = new BookNode;
   name = NULL;
   next = NULL;
}

String BookNode::getName()
{
   return bn->name;
}

void BookNode::setName(String newName)
{
   bn->name = newName;
}

NodePtr getNext()
{
   return *next;
}
---------------------------------------
BookList.h

#include <stdlib.h>
#include <stdio.h>
using namespace std;

#ifndef BOOKLIST_H
#define BOOKLIST_H

class BookList
{
private:
   int listSize;

public:

   NodePtr head, tail;
   BookList *bl;
   
   BookList();
   bool addBook(String name);
   bool deleteBook(NodePtr);
}; 
#endif //BOOKLIST_H
----------------------------------------------
BookList.cpp

#include "BookList.h"
#include "BookNode.h"

BookList::BookList()
{
   head = new Anode;
   current = head;
}

bool BookList::addBook(String name)
{
   ....
   return TRUE;
}

bool BookList::deleteBook(NodePtr)
{
   ....
   return TRUE;
}

Reply With Quote
  #2  
Old August 17th, 2007, 08:41 AM
nattylife nattylife is offline
Closet coder
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2005
Location: Plantation, FL <---south florida
Posts: 1,431 nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 13 h 33 m 57 sec
Reputation Power: 152
Send a message via AIM to nattylife
youve declared Anode as a private member of BookNode. but in BookList, you have:
c Code:
Original - c Code
  1.  
  2. BookList::BookList()
  3. {
  4.    head = new Anode;
  5.    current = head;
  6. }


BookList doesnt know anything about Anode. try defining Anode outside of the class in the header file, then declaring an Anode inside your BookNode.
__________________

Reply With Quote
  #3  
Old August 17th, 2007, 09:19 AM
mantai007 mantai007 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 290 mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 3 h 48 m 33 sec
Reputation Power: 11
i didnt know you can define something out of a class.. because i thought Anoed which is a struct unique to BookNode and should be inside BookNode class...

Reply With Quote
  #4  
Old August 17th, 2007, 09:35 AM
nattylife nattylife is offline
Closet coder
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2005
Location: Plantation, FL <---south florida
Posts: 1,431 nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 13 h 33 m 57 sec
Reputation Power: 152
Send a message via AIM to nattylife
it may be unique but its only unique to BookNode in this case. yet you are trying to create an instance of it in BookList. you would need to define it outside of the class so that BookList can use it also or try a different design.

Reply With Quote
  #5  
Old August 17th, 2007, 09:46 AM
f'lar's Avatar
f'lar f'lar is offline
ASP.Net MVP
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Aug 2003
Location: WI
Posts: 4,378 f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 11 h 5 m 4 sec
Reputation Power: 1509
Send a message via Google Talk to f'lar
He could define it in the class, and use scope resolution to tell the compiler what he wants. ... but he still has to make it public rather than private.
Code:
class BookNode
{
public:
    struct Anode
    {
        String name;
        // ...
    };
    //...
};

class BookList
{
public:
    BookList()
    {
        BookNode::Anode head;
        head.name = "Some book";
    }
};
It seems like what he really wants, though, is to have booknode inherit from Anode or use templates such that he can define Anode generically as a node in a list and have Booknode define the payload for this particular use/application.
Comments on this post
nattylife agrees: didnt even think about that. good point.
__________________
Primary Forum: .Net Development
Holy cow, I'm now an ASP.Net MVP!

[Moving to ASP.Net] | [.Net Dos and Don't for VB6 Programmers]

http://twitter.com/jcoehoorn

Last edited by f'lar : August 17th, 2007 at 09:52 AM.

Reply With Quote
  #6  
Old August 17th, 2007, 09:55 AM
f'lar's Avatar
f'lar f'lar is offline
ASP.Net MVP
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Aug 2003
Location: WI
Posts: 4,378 f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 11 h 5 m 4 sec
Reputation Power: 1509
Send a message via Google Talk to f'lar
Looking more at his code, I think he'll have a real problem when he runs that and tries to create his first instance of a booknode. When the booknode contsructor is first called, if will take bn (a booknode pointer) and create a new instance, which will of course call the booknode constructor which will take it's own bn and create another instance... and on to ifinity, or when memory runs out.

Reply With Quote
  #7  
Old August 17th, 2007, 10:22 AM
mantai007 mantai007 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 290 mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 3 h 48 m 33 sec
Reputation Power: 11
I was originally thinking of creating just 1 Header file to make it simpler...
but that means i have to include the BookList methods as well as the BookNode methods..
So there would need to be 2 classes inside the one header file...

Reply With Quote
  #8  
Old August 17th, 2007, 10:51 AM
nattylife nattylife is offline
Closet coder
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2005
Location: Plantation, FL <---south florida
Posts: 1,431 nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 13 h 33 m 57 sec
Reputation Power: 152
Send a message via AIM to nattylife
flar makes another good point. you will want to rethink your design for the BookNode class. you wont need to have a BookNode as a member of BookNode. BookList will be the one that needs to have those. BookNode only needs enough to create itself and initialize its members.

Reply With Quote
  #9  
Old August 17th, 2007, 10:56 AM
mantai007 mantai007 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 290 mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 3 h 48 m 33 sec
Reputation Power: 11
I see.. i wasnt too sure about the design because.. i have to create a BookList & BookNode class.

and wasnt too sure where to put the BookNode struct.. in the list.cpp or the node.cpp

Reply With Quote
  #10  
Old August 17th, 2007, 12:16 PM
nattylife nattylife is offline
Closet coder
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2005
Location: Plantation, FL <---south florida
Posts: 1,431 nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 13 h 33 m 57 sec
Reputation Power: 152
Send a message via AIM to nattylife
well, your BookList is a list of BookNodes.
while you have a Anode as a member of the BookNode class, do you really need that? couldnt you just have BookNode be the Anode like
c++ Code:
Original - c++ Code
  1.  
  2. class BookNode
  3. {
  4.    private:
  5.       String name;
  6.       BookNode*next;
  7.  
  8.    public:
  9.       BookNode();
  10.       void setBookname(String name);
  11.       String getName();
  12.       BookNode* getNext();
  13. }

that way your BookNode is 1 node object by itself. it contains the name and a pointer to another BookNode. and then BookList can maintain the nodes.
EDIT: out of curiosity, is this an assignment or a learning thing? if its an assignment, you would need to follow the requirements given by your instructor.

Reply With Quote
  #11  
Old August 17th, 2007, 08:12 PM
mantai007 mantai007 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 290 mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 3 h 48 m 33 sec
Reputation Power: 11
Oh hmm i thought link list nodes need to be in a struct...

Reply With Quote
  #12  
Old August 17th, 2007, 08:30 PM
mantai007 mantai007 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 290 mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 3 h 48 m 33 sec
Reputation Power: 11
Yes it is an assignment...
Because i have to create the following classes...
"BookList"
"BookNode"
"Book"
and others.. thats why i got a little confused, so i wasnt sure to create 2 header files, one for booknode and booklist...

Reply With Quote
  #13  
Old August 17th, 2007, 11:04 PM
nattylife nattylife is offline
Closet coder
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2005
Location: Plantation, FL <---south florida
Posts: 1,431 nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 13 h 33 m 57 sec
Reputation Power: 152
Send a message via AIM to nattylife
its totally possible to make a node out of a struct. but from the looks of your assignment, i think they want you to go with the class way that i mentioned. but you can always verify with your instructor. their requirements are what you need to base it on. it never hurts to ask advice from them on your design and such also to make sure you are on the same wavelength with the instructor.

Reply With Quote
  #14  
Old August 17th, 2007, 11:20 PM
mantai007 mantai007 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 290 mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 3 h 48 m 33 sec
Reputation Power: 11
yeah i made it into a class it seems simpler that way.. ill ask my tutor on monday and verify it..

Reply With Quote
  #15  
Old August 18th, 2007, 05:01 AM
mantai007 mantai007 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 290 mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level)mantai007 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 3 h 48 m 33 sec
Reputation Power: 11
ive implemented it now and it works.. i just looked at f'lar code and created BookNode as a class.. so its all working now.

thanks guys for the input.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Cannot access struct in h file

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap