A
arnuld
-------- PROGRAMME -----------
/* Stroustrup, 5.6 Structures
STATEMENT:
this programmes *tries* to do do this in 3 parts:
1.) it creates a "struct", named "jd", of type "address".
2. it then adds values to "jd"
3.) in the end it prints values of "jd".
*/
#include<iostream>
#include<vector>
struct address;
void fill_addr(address); // assigns values to a struct of type
"address"
void print_addr(address*); // prints an address struct
struct address {
char* name;
char* country;
};
int main()
{
address jd; // an "address" struct
fill_addr(jd);
print_addr(jd);
return 0;
}
struct* fill_addr(address* jd)
{
jd.name = "Niklaus Wirth";
jd.country = "Switzerland";
return jd;
}
void print_addr(address* p)
{
using std::cout;
using std::endl;
cout << p->name
<< '\n'
<< p->country
<< endl;
}
----------- OUTPUT --------------
[arch@voodo tc++pl]$ g++ -ansi -pedantic -Wall -Wextra
5.6_structures.cpp
5.6_structures.cpp: In function 'int main()':
5.6_structures.cpp:30: error: cannot convert 'address' to 'address*'
for argument '1' to 'void print_addr(address*)'
5.6_structures.cpp: At global scope:
5.6_structures.cpp:36: error: expected identifier before '*' token
5.6_structures.cpp: In function 'int* fill_addr(address*)':
5.6_structures.cpp:38: error: request for member 'name' in 'jd', which
is of non-class type 'address*'
5.6_structures.cpp:39: error: request for member 'country' in 'jd',
which is of non-class type 'address*'
5.6_structures.cpp:41: error: cannot convert 'address*' to 'int*' in
return
[arch@voodo tc++pl]$
i know the error at "line 30" means but i am not able to correct it. i
tried with different ways of using "address" and "address*" but it
does not work :-(
/* Stroustrup, 5.6 Structures
STATEMENT:
this programmes *tries* to do do this in 3 parts:
1.) it creates a "struct", named "jd", of type "address".
2. it then adds values to "jd"
3.) in the end it prints values of "jd".
*/
#include<iostream>
#include<vector>
struct address;
void fill_addr(address); // assigns values to a struct of type
"address"
void print_addr(address*); // prints an address struct
struct address {
char* name;
char* country;
};
int main()
{
address jd; // an "address" struct
fill_addr(jd);
print_addr(jd);
return 0;
}
struct* fill_addr(address* jd)
{
jd.name = "Niklaus Wirth";
jd.country = "Switzerland";
return jd;
}
void print_addr(address* p)
{
using std::cout;
using std::endl;
cout << p->name
<< '\n'
<< p->country
<< endl;
}
----------- OUTPUT --------------
[arch@voodo tc++pl]$ g++ -ansi -pedantic -Wall -Wextra
5.6_structures.cpp
5.6_structures.cpp: In function 'int main()':
5.6_structures.cpp:30: error: cannot convert 'address' to 'address*'
for argument '1' to 'void print_addr(address*)'
5.6_structures.cpp: At global scope:
5.6_structures.cpp:36: error: expected identifier before '*' token
5.6_structures.cpp: In function 'int* fill_addr(address*)':
5.6_structures.cpp:38: error: request for member 'name' in 'jd', which
is of non-class type 'address*'
5.6_structures.cpp:39: error: request for member 'country' in 'jd',
which is of non-class type 'address*'
5.6_structures.cpp:41: error: cannot convert 'address*' to 'int*' in
return
[arch@voodo tc++pl]$
i know the error at "line 30" means but i am not able to correct it. i
tried with different ways of using "address" and "address*" but it
does not work :-(