Home > Back-end >  C typedef definition used in the structure of how the output operator overloading
C typedef definition used in the structure of how the output operator overloading

Time:09-23

I defines a structure like this:


I was in the main function of the output when the structure variables:
 
Edges ele.
Ele. Index_begin=10;
Ele. Index_end=20;
Ele. Weight=30;
STD: : cout & lt; <"Edges" & lt;


But such a compiler error error: 'Edges' does not name a type,

I now put the typedef struct definition alone behind, you can normal compile


Why is this? If you want to define the structure while typedef, then the overloaded function should be how to write? To help explain the trouble friends,

CodePudding user response:

C + +, it is necessary to go to the typedef struct X {} Y?

Struct Y {

Friend STD: : ostream& Operator<(STD: : ostream& The const Y& ) {

}
}

CodePudding user response:

Typedef struct {X

Friend STD: : ostream& Operator<(STD: : ostream& The const X& ) {//here can only use the X, because Y haven't appeared,

}

} Y;

CodePudding user response:

reference 1st floor SDGHCHJ response:
c + +, it is necessary to typedef struct X {} Y?

Struct Y {

Friend STD: : ostream& Operator<(STD: : ostream& The const Y& ) {

}
}

The writing should be no? I tried it on or error, prompt Y does not name a type
If this can use convenient

CodePudding user response:

The
reference 3 floor StrugglePeach response:
this writing should not line? I tried it on or error, prompt Y does not name a type
If this can use convenient


Don't is your top floor of the second kind of writing

CodePudding user response:

reference 4 floor SDGHCHJ response:
Quote: reference StrugglePeach reply: 3/f

The writing should be no? I tried it on or error, prompt Y does not name a type
If this can use convenient


Is it not you top the second written

I have a second behind or writing typdef alone, or still won't do,

CodePudding user response:

reference 5 floor StrugglePeach reply:
Quote: refer to 4th floor SDGHCHJ response:

Quote: refer to the third floor StrugglePeach response:

The writing should be no? I tried it on or error, prompt Y does not name a type
If this can use convenient


Is it not you top the second written

I have a second behind or writing typdef alone, or still won't do,


What is the relationship between typedef??? If so, your compiler can be lost,

CodePudding user response:

refer to 6th floor SDGHCHJ response:
Quote: refer to the fifth floor StrugglePeach reply:

Quote: refer to 4th floor SDGHCHJ response:

Quote: refer to the third floor StrugglePeach response:

The writing should be no? I tried it on or error, prompt Y does not name a type
If this can use convenient


Is it not you top the second written

I have a second behind or writing typdef alone, or still won't do,


What is the relationship between typedef??? If so, your compiler can lost,


Ha ha, is my problem, you're right, direct struct Y {
Friend STD: : ostream& Operator<(STD: : ostream& The const Y& ) {}
};
And then later can use Y define variables, thanks a lot
  • Related