CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2012
    Location
    Slovenia
    Posts
    259

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Apr 2012
    Location
    Slovenia
    Posts
    259

    Re: Qtcreator finds an error outside of program

    Now it works for me too, after i type

    Code:
    CONFIG += c++11
    in the .pro file.
    Last edited by flex567; September 20th, 2014 at 12:42 PM.

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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
  •  





Click Here to Expand Forum to Full Width

Featured