error C2027 ?
-
Hi! i define two structs in .h file:
struct s1
{
CString str;
struct s2* ss2;
};
struct s2
{
int i;
CString name;
};and in .cpp file, in a function i use of this structs:
s1 myS;
myS.str = "";
myS.ss2->i = 0; // error C2027: use of undefined type s2please help me, how do i solve this error?
Zo.Naderi-Iran
-
Hi! i define two structs in .h file:
struct s1
{
CString str;
struct s2* ss2;
};
struct s2
{
int i;
CString name;
};and in .cpp file, in a function i use of this structs:
s1 myS;
myS.str = "";
myS.ss2->i = 0; // error C2027: use of undefined type s2please help me, how do i solve this error?
Zo.Naderi-Iran
Put struct s2 before struct s1,
struct s2
{
int i;
CString name;
};struct s1
{
CString str;
struct s2* ss2;
};«_Superman_»
I love work. It gives me something to do between weekends. -
Hi! i define two structs in .h file:
struct s1
{
CString str;
struct s2* ss2;
};
struct s2
{
int i;
CString name;
};and in .cpp file, in a function i use of this structs:
s1 myS;
myS.str = "";
myS.ss2->i = 0; // error C2027: use of undefined type s2please help me, how do i solve this error?
Zo.Naderi-Iran
ohhhhhhhh, my problem was solved; the problem is in struct name. the struct name was incorrect in my code.
struct s1
{
CString str;
struct z2* ss2; // the correct struct name is s2
};
struct s2
{
int i;
CString name;
};and the error was : error C2027: use of undefined type z2 when i Write in code project, this code, i Pay attention this problem. thank you and excuse me,
Zo.Naderi-Iran
-
Put struct s2 before struct s1,
struct s2
{
int i;
CString name;
};struct s1
{
CString str;
struct s2* ss2;
};«_Superman_»
I love work. It gives me something to do between weekends.«_Superman_» wrote:
Put struct s2 before struct s1,
This won't make any difference.
Software rusts. Simon Stephenson, ca 1994.
-
«_Superman_» wrote:
Put struct s2 before struct s1,
This won't make any difference.
Software rusts. Simon Stephenson, ca 1994.
-
«_Superman_» wrote:
Put struct s2 before struct s1,
This won't make any difference.
Software rusts. Simon Stephenson, ca 1994.
SuperMan is right, there are two way to solve above problem apart from actual problem
(Struct Name mismatch)
. 1. As Mentioned by Superman 2. Forward Declaration ! like thisstruct s2; //forward Declaration
struct s1
{
CString str;
struct s2* ss2;
};struct s2
{
int i;
CString name;
};"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You
-
Peter_in_2780 wrote:
This won't make any difference.
Try it.
It's time for a new signature.
Richard MacCutchan wrote:
Try it.
#include <iostream.h>
struct a {
int aa;
struct b *pb;
};
struct b {
int bb;
struct a *pa;
};#pragma argsused
int main(int argc, char* argv[])
{
struct a *xa = new struct a;
struct b *xb = new struct b;
xa->pb = xb;
xa->pb->bb = 5;
cout << xb->bb;
return 0;
}compiles and runs in my world. OK, so I'm not (M$) politically correct - I'm currently using Borland Turbo C++. I vaguely remember K&R or Stroustrup talking about this kind of forward reference - a pointer is as big as a pointer, regardless of what it points to, so all the compiler has to do is accept the implicit declaration. btw, I don't want to get into a flame war about standards and compliance. :) [edit][rant]However, I do think the 1-votes are unwarranted. Note that the OP's problem was *never* with the struct definitions, but turned out to be a typo in later reference. Two of you jumped down my throat. Personally, I don't give a flying, but the youngsters watching this might get the wrong impression.[/rant][/edit]
Software rusts. Simon Stephenson, ca 1994.
modified on Tuesday, July 27, 2010 12:39 AM
-
Richard MacCutchan wrote:
Try it.
#include <iostream.h>
struct a {
int aa;
struct b *pb;
};
struct b {
int bb;
struct a *pa;
};#pragma argsused
int main(int argc, char* argv[])
{
struct a *xa = new struct a;
struct b *xb = new struct b;
xa->pb = xb;
xa->pb->bb = 5;
cout << xb->bb;
return 0;
}compiles and runs in my world. OK, so I'm not (M$) politically correct - I'm currently using Borland Turbo C++. I vaguely remember K&R or Stroustrup talking about this kind of forward reference - a pointer is as big as a pointer, regardless of what it points to, so all the compiler has to do is accept the implicit declaration. btw, I don't want to get into a flame war about standards and compliance. :) [edit][rant]However, I do think the 1-votes are unwarranted. Note that the OP's problem was *never* with the struct definitions, but turned out to be a typo in later reference. Two of you jumped down my throat. Personally, I don't give a flying, but the youngsters watching this might get the wrong impression.[/rant][/edit]
Software rusts. Simon Stephenson, ca 1994.
modified on Tuesday, July 27, 2010 12:39 AM
Well I did not jump down your throat, nor did I 1-vote you. I merely challenged your assertion that changing the order of the declarations would not make any difference. I do agree with you that we don't want to start a flame war with this.
It's time for a new signature.