|
See this[^] thread.
Steve
|
|
|
|
|
I use forwarding references in C++ but I need them in C with structs and it does not work:
struct _BB;
typedef struct _AA {
BB* bb; //error
int a;
} AA, *PAA;
typedef struct _BB {
AA* aa; //error
int b;
} BB, *PBB;
chesnokov
|
|
|
|
|
Try something like this:
"A.h":
#ifndef __A_H__INCLUDED__
#define __A_H__INCLUDED__
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
typedef struct tagB B;
typedef struct tagA
{
B *pB;
} A;
#endif // !__A_H__INCLUDED__
"B.h":
#ifndef __B_H__INCLUDED__
#define __B_H__INCLUDED__
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
typedef struct tagA A;
typedef struct tagB
{
A *pA;
} B;
#endif // !__B_H__INCLUDED__
Steve
|
|
|
|
|
I'll see if it will solve the next problem!
That one compiles:
struct BB;
typedef struct _AA {
struct BB* bb;
int a;
} AA, *PAA;
typedef struct _BB {
struct AA* aa;
int b;
} BB, *PBB;
But you can not access BBs contents using AA object??
AA aa;
aa.a = 1;
aa.bb->b = 1; //error???? Ahhhh
chesnokov
|
|
|
|
|
Chesnokov Yuriy wrote: aa.bb->b = 1; //error???? Ahhhh
Should be as follows:
aa->bb->b = 1;
Steve
|
|
|
|
|
You have a lot of patience, man. My 5 .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
No way
AA aa;
aa->bb??? how can you access with -> object on stack not a pointer??
the glitch is
struct BB;
typedef struct _AA {
struct BB* bb;
int a;
} AA, *PAA;
typedef struct _BB {
struct AA* aa;
int b;
} BB, *PBB;
that one works but you can not access bbs constents from AA nor vice versa?
chesnokov
|
|
|
|
|
Yeah, you're right. So what's your problem exactly?
Steve
|
|
|
|
|
to compile and run that code:
struct BB;
typedef struct _AA {
struct BB* bb;
int a;
} AA, *PAA;
typedef struct _BB {
struct AA* aa;
int b;
} BB, *PBB;
main()
{
AA a;
BB b;
a.bb = &b;
b.aa = &a;
a.bb->b = 1;
b.aa->a = 3;
}
chesnokov
|
|
|
|
|
This works fine for me:
#include "stdafx.h"
struct BB;
struct AA
{
struct BB* bb;
int a;
};
struct BB
{
struct AA* aa;
int b;
};
void main()
{
struct AA a;
struct BB b;
a.bb = &b;
b.aa = &a;
a.bb->b = 1;
b.aa->a = 3;
}
Steve
|
|
|
|
|
You're having trouble with them being declared as pointers, and want them as real contained structs.
To borrow a phrase, "Imagine if you could do what you're asking".
AA would contain a BB which would contain an AA which would contain a BB which would contain an AA which would contain a BB which would contain an AA which would contain a BB which would contain an AA which would contain a BB which would contain an AA which would contain a BB which would contain an AA which would contain a BB which would contain an AA which would contain a BB...
I hope I'm getting the point across - I'm bored of typing. But your structure would end up infinitely large.
You can contain a *pointer* to your structures evil twin - a pointer only takes up a few bytes. But you need to give the pointer something to point to.
So:
struct BB;
struct AA
{
struct BB *bb;
int a;
};
struct BB
{
struct AA *aa;
int b;
};
main ()
{
AA a;
BB b;
a.bb->b = 1;
}
In the above example, C isn't psychic, so hasn't pointed A.bb at any BB structure. How can it? That's your job.
Try the below code.
AA a;
BB b;
a.bb = &b;
b.aa = &a;
a.bb->b = 1;
b.aa->a = 3;
Now your two structure can talk to each other to their heart's content.
I'd go back to your C book, and look up linked lists - it'll give you a light bulb moment about pointers.
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
Iain Clarke wrote: I'd go back to your C book
If any.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Do not push to other limits I know to self refere them in future the glitch is it does not compile??
Try it yourself:
AA a;
BB b;
a.bb = &b;
b.aa = &a;
a.bb->b = 1; //error C2037
b.aa->a = 3; //error C2037
chesnokov
|
|
|
|
|
My apologies, I hadn't fully switched off my C++ brain.
try:
struct AA a;
struct BB b;
a.bb = &b;
b.aa = &a;
a.bb->b = 1;
b.aa->a = 3;
Though you could have worked that out for yourself...
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
Iain Clarke wrote: Though you could have worked that out for yourself...
Another hint the C book was lost sometime.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Good day Guys,
Just would like to ask for help on this, how do I disable a tab in CTabCtrl?
I have a custom class extending CTabCtrl for some processing and also 3 Dialogs as Tabs.
On runtime, while processing on one tab, I would like to disable the other 3 tabs as not to mess
with the processing.
Thanks in advance
rbmarasigan2001
|
|
|
|
|
My first thought was "what a lazy question! Just called CTabCtrl::EnableItem (n, FALSE), or SetStyle (some struct with enable flag turned off)"...
But neither CTabCtrl, or (more authoratively) appear to have any disable tab functionality.
In my software, I don't use CTabCtrl as such - I use CFolderTabCtrl written by Paul diLascia in October 2002's MSDN magazine. Lot's of nice goodies in it, which hopefully will help you. You may even find it has the functionality you've added yourself...
http://msdn.microsoft.com/en-us/magazine/cc188936.aspx[^]
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
Hi every one!
I have started a project using ciphering. That is going to be my last project in my school!
My teacher has told me this project is going to be published with no fee in the internet.
I want to use RSA and SHA1 taken by XYSSL Cristophe's Devine project (you may know : www.xyssl.org)
and make some modifications. How can do it so as to make it by low?
Also: What does it mean XYSSL having GPL license?
thanks!
|
|
|
|
|
See here[^] Im not sure its helpful for you or no?
|
|
|
|
|
|
Dennis L wrote: My teacher has told me this project is going to be published with no fee in the internet.
Not really a programming answer, but this seems a bit wrong to me. Surely this is work that you will create - it's valid for your teacher to mark it, and maybe keep confidential copies for reference in case someone challenges her marks - but why does she have a right to give your work to the world?
If *you* allowed it to be published to the world, then great. I've written some articles here, and am happy to give back to the greater community. But I'd be peeved if I had no choice about it.
Would you fail if you handed in the code with "Copyright Dennis L, not GPL, not using GPL, and not to be published without permission" on the top of every page?
Saying that, if you use GPL components, their license will infect your code too, I suppose.
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
I have problems compiling my project.
There a two header-files:
the first one, ClassA.h:
#include "ClassB.h"
class ClassA
{
...
private:
ClassB classB;
...
}
and the second, ClassB.h:
#include "ClassA.h"
class ClassB
{
...
private:
ClassA classA;
...
}
So ClassA requires ClassB and ClassB requires ClassA.
The Compiler doesnt semm to like this kind of cross-requirements.
How can i solve this problem?
|
|
|
|
|
The way you're going about things doesn't make sense if you think about it. If Class A contains an instance of Class B and Class B contains an instance of Class A you've got something akin to infinite recursion. Perhaps this diagram will clarify this:
Class A
{
Class B
{
Class A
{
Class B
{
Class A
{
.
.
.
}
}
}
}
}
Steve
|
|
|
|
|
Why vote down this you clowns? This post explains why the approach doesn't make sense and the next suggests a solution.
Steve
|
|
|
|
|
"Vote me down, and I shall become more popular than you can imagine!"
Maybe the thought of an infinite struct blew their minds?
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|