I have a class like this:
<LarryClass.h >
class LarryClass {
public:
struct MoeLinkedListSt ruct {
LarryClass *Larry;
float MoeValue;
MoeLinkedListSt ruct *NextMoe;
};
LarryClass();
~LarryClass();
void Eval(float Value, MoeLinkedListSt ruct *&MoePtr);
private:
.....
}
I also have another class wherein I would like to be able to dynamically
create a new MoeLinkedListSt ruct like this:
<MoeClass.h>
#include "LarryClass .h"
<MoeClass.cpp >
MoeLinkedListSt ruct *MoePtr = new MoeLinkedListSt ruct;
LarryClass *Larry = new LarryClass;
Larry->Eval(0,MoePtr) ;
So the question is this: how do I make the MoeLinkedListSt ruct visible to
LarryClass? Since the struct is defined in the public area of LarryClass,
shouldn't the above code work? Am I just missing something small? I can't
really put the structure definition into a different file, because it has a
LarryClass variable in it, so LarryClass must already be defined. What else
could I do here? By the way, the intent here is for the Eval function in
LarryClass to be able to modify MoePtr to point to a different Moe, and then
pass that back up to the MoeClass.
Thanks, Vic 1 2923
"Victor Hannak" <victor.hannak@ no****@rocheste r.rr.com> wrote in message
news:7J******** ***********@twi ster.nyroc.rr.c om... I have a class like this: <LarryClass.h > class LarryClass {
public: struct MoeLinkedListSt ruct { LarryClass *Larry; float MoeValue; MoeLinkedListSt ruct *NextMoe; }; LarryClass(); ~LarryClass(); void Eval(float Value, MoeLinkedListSt ruct *&MoePtr);
private: .... }
I also have another class wherein I would like to be able to dynamically create a new MoeLinkedListSt ruct like this: <MoeClass.h> #include "LarryClass .h"
<MoeClass.cpp > MoeLinkedListSt ruct *MoePtr = new MoeLinkedListSt ruct; LarryClass *Larry = new LarryClass; Larry->Eval(0,MoePtr) ;
So the question is this: how do I make the MoeLinkedListSt ruct visible to LarryClass? Since the struct is defined in the public area of LarryClass, shouldn't the above code work? Am I just missing something small?
This should work.
LarryClass::Moe LinkedListStruc t *MoePtr = new
LarryClass::Moe LinkedListStruc t;
I can't really put the structure definition into a different file, because it has
a LarryClass variable in it, so LarryClass must already be defined.
Not true, because MoeLinkedListSt ruct only has a pointer to LarryClass you
could use a forward declaration.
class LarryClass; // forward declaration
struct MoeLinkedListSt ruct {
LarryClass *Larry;
float MoeValue;
MoeLinkedListSt ruct *NextMoe;
};
This will compile without LarryClass being fully defined.
john This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steve |
last post by:
I'll be the first to admit, I'm not entirely clear on the appropriate
usage of either.
From what I am reading in my books, a Struct and a Class are pretty
much the same, with the difference being, a Class can have private and
protected members, but a Struct everything is Public by default.
I laymans terms what would be an appropriate reason to choose a Struct
over a Class?
So why would one want to choose a Class over a Struct.
|
by: Dan |
last post by:
Hello,
I have trouble with class calling. I am calling getvolume() with succes in
the function CreateCircle but it do not want to call it in ShowCircle()
function. I am staying in the same class. I thought that was the point of
encapsulation. When the function ShowCircle() is called I get very large
number -1.07374e+008
can anyone help me ?
|
by: Steven T. Hatton |
last post by:
The following may strike many of you as just plain silly, but it represents
the kind of delelima I find myself in when trying to make a design
decision. This really is a toy project written for the purpose of learning
to work with C++. It therefore makes some sense for me to give the
situation the amount of consideration presented below. To be quite honest,
I'm amazed at the amount there is to say about such a seemingly simple...
|
by: surrealtrauma |
last post by:
i have a trouble about that:
i want to ask user to enter the employee data (employee no., name, worked
hour, etc.), but i dont know how to sort the data related to a particular
employee as a group. i want to use a array object in the class but i don't
know how..i am just learning the c++. So i dont know how to use class. in
fact, i have writen like the following:
class employee {
public:
employee();
|
by: Chris |
last post by:
Hi,
I don't get the difference between a struct and a class !
ok, I know that a struct is a value type, the other a reference type, I
understand the technical differences between both, but conceptually speaking
: when do I define something as 'struct' and when as 'class' ?
for example : if I want to represent a 'Time' thing, containing :
- data members : hours, mins, secs
| |
by: thomson |
last post by:
Hi all,
Would you please explain me where will be the heap stored if it
is declared inside the Class, As class is a reference type, so it gets
stored on the heap, but struct is a value type-stored on the stack
Regards
thomson
|
by: Martin Jørgensen |
last post by:
Hi,
Consider this code:
--- beginning of code ---
#include <iostream>
using namespace std;
class Child{
public:
|
by: Steven T. Hatton |
last post by:
This is not a big deal. It just bothers me that I don't see a way around
including the header for QVariant in the following:
#ifndef _XML_IMPL_INTERNAL_H_
#define _XML_IMPL_INTERNAL_H_
class QString;
class QVariant;
namespace xml_impl {
|
by: Ninereeds |
last post by:
I'm messing around with using mixin-layers (look for papers by Yannis
Smaragdakis and Don Batory) to define data structures. One issue is
that nodes tend to have pointers to other nodes - the pointers have to
point to the full node type, and have to be referenced before that
full node type is known.
One solution is to use the 'fixpoint construction' to get an apparent
circular dependency...
class c_Final : public c_Layer2< c_Layer1...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |