-
September 20th, 2014, 12:12 PM
#1
Qtcreator finds an error outside of program
Code:
// incomplete-types.cpp by Bill Weinman <http://bw.org/>
#include <iostream>
#include <vector>
using namespace std;
struct Child; // incomplete type
struct Parent {
string name;
vector<Child *> children; // we don't need to know the details heres
};
// complete the definition of Child
struct Child {
string name;
vector<Parent *> parents;
};
void printChildren (Parent *);
void printParents (Child *);
int main( int argc, char ** argv ) {
Parent dad = { "George" };
Parent mom = { "Jane" };
Child judy = { "Judy" };
Child elroy = { "Elroy" };
dad.children = { &judy, &elroy };
mom.children = { &judy, &elroy };
judy.parents = { &mom, &dad };
elroy.parents = { &mom, &dad };
printChildren(&dad);
printChildren(&mom);
printParents(&judy);
printParents(&elroy);
cout << endl;
return 0;
}
void printChildren (Parent * p) {
cout << p->name;
cout << " has children: ";
vector<Child *> c = p->children;
vector<Child *>::iterator i;
for( i = c.begin(); i < c.end(); i++ ) {
cout << (*i)->name;
if((i + 1) != c.end()) {
cout << ", ";
}
}
cout << endl;
}
void printParents (Child * c) {
cout << c->name ;
cout << " has parents: ";
vector<Parent *> p = c->parents;
vector<Parent *>::iterator i;
for( i = p.begin(); i < p.end(); i++ ) {
cout << (*i)->name;
if((i + 1) != p.end()) {
cout << ", ";
}
}
cout << endl;
}
Why this program wont compile?
Last edited by flex567; September 20th, 2014 at 12:14 PM.
-
September 20th, 2014, 12:21 PM
#2
Re: Qtcreator finds an error outside of program
It compiles without even a warning for me, at least when I compile with respect to C++11 on g++ 4.8.2. You might want to post the error messages too.
-
September 20th, 2014, 12:35 PM
#3
Re: Qtcreator finds an error outside of program
Now it works for me too, after i type
in the .pro file.
Last edited by flex567; September 20th, 2014 at 12:42 PM.
-
September 20th, 2014, 02:21 PM
#4
Re: Qtcreator finds an error outside of program
Just for info - it doesn't compile with VS2013! The first errors are from
Code:
dad.children = { &judy, &elroy };
mom.children = { &judy, &elroy };
judy.parents = { &mom, &dad };
elroy.parents = { &mom, &dad };
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|