使用向量的基本c ++函数

时间:2015-09-22 20:02:30

标签: c++ vector

我正在用矢量做一些练习。我创建了一个填充定义大小的向量的函数,但是当我尝试将其设置为CompileSwift normal x86_64 /Users/satre/Developer/Projects/STSI/MedConf/Event.swift cd /Users/satre/Developer/Projects/STSI /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/satre/Developer/Projects/STSI/MedConf/SpeakerDetailsViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/AboutUsViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/AttendeeCell.swift /Users/satre/Developer/Projects/STSI/MedConf/ConfirmNewProfileImageViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/SurveyViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/NotificationsTableViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/SponsorWebsiteViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/FavoritesTableViewController.swift /Users/satre/Developer/Projects/STSI/AgendaViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/AppDelegate.swift /Users/satre/Developer/Projects/STSI/MedConf/Sponsor.swift /Users/satre/Developer/Projects/STSI/MedConf/CustomNavController.swift /Users/satre/Developer/Projects/STSI/MedConf/StickyNotification.swift /Users/satre/Developer/Projects/STSI/MedConf/MoreInfoViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/TravelVC.swift /Users/satre/Developer/Projects/STSI/MedConf/SponsorsTableViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/SpeakerCell.swift /Users/satre/Developer/Projects/STSI/MedConf/BasicNavController.swift -primary-file /Users/satre/Developer/Projects/STSI/MedConf/Event.swift /Users/satre/Developer/Projects/STSI/MedConf/PublicConstants.swift /Users/satre/Developer/Projects/STSI/MedConf/Attendee.swift /Users/satre/Developer/Projects/STSI/MedConf/Conference.swift /Users/satre/Developer/Projects/STSI/MedConf/ConfInfoViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/DBQuestion.swift /Users/satre/Developer/Projects/STSI/MedConf/TravelBusiness.swift /Users/satre/Developer/Projects/STSI/MedConf/MyAcountPrefsTableViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/PeopleViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/EventDetailsViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/SideMenuTableVC.swift /Users/satre/Developer/Projects/STSI/MedConf/Speaker.swift /Users/satre/Developer/Projects/STSI/MedConf/NotificationManager.swift /Users/satre/Developer/Projects/STSI/MedConf/QRViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/ConfListTableViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/DiscussionBoard.swift /Users/satre/Developer/Projects/STSI/MedConf/ENSideMenu.swift /Users/satre/Developer/Projects/STSI/MedConf/Session.swift /Users/satre/Developer/Projects/STSI/MedConf/QRWebViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/ManTabBarController.swift /Users/satre/Developer/Projects/STSI/MedConf/ObjectManager.swift /Users/satre/Developer/Projects/STSI/MedConf/ColoredSegmentButton.swift /Users/satre/Developer/Projects/STSI/MedConf/DBManager.swift /Users/satre/Developer/Projects/STSI/MedConf/ENSideMenuNavigationController.swift -target x86_64-apple-ios8.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk -I /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Products/Debug-iphonesimulator -F /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Products/Debug-iphonesimulator -F /Users/satre/Developer/Projects/STSI -F /Users/satre/Developer/Projects/STSI/MedConf -F /Users/satre/Downloads/parse-library-1 -enable-testing -g -import-objc-header /Users/satre/Developer/Projects/STSI/MedConf-Bridging-Header.h -module-cache-path /Users/satre/Library/Developer/Xcode/DerivedData/ModuleCache -D COCOAPODS -serialize-debugging-options -Xcc -I/Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/STSI-generated-files.hmap -Xcc -I/Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/STSI-own-target-headers.hmap -Xcc -I/Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/STSI-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/STSI-project-headers.hmap -Xcc -I/Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/DerivedSources/x86_64 -Xcc -I/Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -DCOCOAPODS=1 -Xcc -working-directory/Users/satre/Developer/Projects/STSI -emit-module-doc-path /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/Objects-normal/x86_64/Event~partial.swiftdoc -Onone -module-name STSI -emit-module-path /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/Objects-normal/x86_64/Event~partial.swiftmodule -serialize-diagnostics-path /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/Objects-normal/x86_64/Event.dia -emit-dependencies-path /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/Objects-normal/x86_64/Event.d -emit-reference-dependencies-path /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/Objects-normal/x86_64/Event.swiftdeps -o /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/Objects-normal/x86_64/Event.o 0 swift 0x000000010cc2cedb llvm::sys::PrintStackTrace(__sFILE*) + 43 1 swift 0x000000010cc2d61b SignalHandler(int) + 379 2 libsystem_platform.dylib 0x00007fff91811f1a _sigtramp + 26 3 libsystem_platform.dylib 0x00007fff54ec0d50 _sigtramp + 3278564944 4 swift 0x000000010b4038d5 swift::Type::transform(std::__1::function<swift::Type (swift::Type)> const&) const + 53 5 swift 0x000000010b245086 swift::constraints::ConstraintSystem::simplifyType(swift::Type, llvm::SmallPtrSet<swift::TypeVariableType*, 16u>&) + 54 6 swift 0x000000010b266cba swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 2362 7 swift 0x000000010b2693cf swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 143 8 swift 0x000000010b2c3bfc swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 732 9 swift 0x000000010b2c87ba swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*) + 474 10 swift 0x000000010b26e366 (anonymous namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<TCCFlags, unsigned int>) + 806 11 swift 0x000000010b26c2cf swift::ASTVisitor<(anonymous namespace)::FailureDiagnosis, bool, void, void, void, void, void>::visit(swift::Expr*) + 4863 12 swift 0x000000010b2665c0 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 576 13 swift 0x000000010b2693cf swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 143 14 swift 0x000000010b2c3bfc swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 732 15 swift 0x000000010b2c87ba swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*) + 474 16 swift 0x000000010b26e366 (anonymous namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<TCCFlags, unsigned int>) + 806 17 swift 0x000000010b26f305 std::__1::__function::__func<(anonymous namespace)::FailureDiagnosis::visitExpr(swift::Expr*)::$_9, std::__1::allocator<(anonymous namespace)::FailureDiagnosis::visitExpr(swift::Expr*)::$_9>, void (swift::Expr*)>::operator()(swift::Expr*&&) + 37 18 swift 0x000000010b3c8547 swift::Expr::forEachChildExpr(std::__1::function<void (swift::Expr*)> const&)::ChildWalker::walkToExprPre(swift::Expr*) + 39 19 swift 0x000000010b36dfa2 (anonymous namespace)::Traversal::visit(swift::Expr*) + 2610 20 swift 0x000000010b36cc85 swift::Expr::walk(swift::ASTWalker&) + 53 21 swift 0x000000010b3c61fc swift::Expr::forEachChildExpr(std::__1::function<void (swift::Expr*)> const&) + 44 22 swift 0x000000010b26c098 swift::ASTVisitor<(anonymous namespace)::FailureDiagnosis, bool, void, void, void, void, void>::visit(swift::Expr*) + 4296 23 swift 0x000000010b2665c0 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 576 24 swift 0x000000010b2693cf swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 143 25 swift 0x000000010b2c3bfc swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 732 26 swift 0x000000010b2c87ba swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*) + 474 27 swift 0x000000010b26e366 (anonymous namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<TCCFlags, unsigned int>) + 806 28 swift 0x000000010b266583 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 515 29 swift 0x000000010b2693cf swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 143 30 swift 0x000000010b2c3bfc swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 732 31 swift 0x000000010b2c87ba swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*) + 474 32 swift 0x000000010b31ae5b swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 411 33 swift 0x000000010b3199b2 swift::TypeChecker::typeCheckFunctionBodyUntil(swift::FuncDecl*, swift::SourceLoc) + 370 34 swift 0x000000010b31a2d3 swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 179 35 swift 0x000000010b2b43b2 typeCheckFunctionsAndExternalDecls(swift::TypeChecker&) + 242 36 swift 0x000000010b2b50f7 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int) + 1831 37 swift 0x000000010b104224 swift::CompilerInstance::performSema() + 4340 38 swift 0x000000010ad3b605 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 741 39 swift 0x000000010ad3b10a frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2682 40 swift 0x000000010ad37797 main + 2247 41 libdyld.dylib 0x00007fff99c895c9 start + 1 Stack dump: 0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/satre/Developer/Projects/STSI/MedConf/SpeakerDetailsViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/AboutUsViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/AttendeeCell.swift /Users/satre/Developer/Projects/STSI/MedConf/ConfirmNewProfileImageViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/SurveyViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/NotificationsTableViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/SponsorWebsiteViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/FavoritesTableViewController.swift /Users/satre/Developer/Projects/STSI/AgendaViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/AppDelegate.swift /Users/satre/Developer/Projects/STSI/MedConf/Sponsor.swift /Users/satre/Developer/Projects/STSI/MedConf/CustomNavController.swift /Users/satre/Developer/Projects/STSI/MedConf/StickyNotification.swift /Users/satre/Developer/Projects/STSI/MedConf/MoreInfoViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/TravelVC.swift /Users/satre/Developer/Projects/STSI/MedConf/SponsorsTableViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/SpeakerCell.swift /Users/satre/Developer/Projects/STSI/MedConf/BasicNavController.swift -primary-file /Users/satre/Developer/Projects/STSI/MedConf/Event.swift /Users/satre/Developer/Projects/STSI/MedConf/PublicConstants.swift /Users/satre/Developer/Projects/STSI/MedConf/Attendee.swift /Users/satre/Developer/Projects/STSI/MedConf/Conference.swift /Users/satre/Developer/Projects/STSI/MedConf/ConfInfoViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/DBQuestion.swift /Users/satre/Developer/Projects/STSI/MedConf/TravelBusiness.swift /Users/satre/Developer/Projects/STSI/MedConf/MyAcountPrefsTableViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/PeopleViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/EventDetailsViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/SideMenuTableVC.swift /Users/satre/Developer/Projects/STSI/MedConf/Speaker.swift /Users/satre/Developer/Projects/STSI/MedConf/NotificationManager.swift /Users/satre/Developer/Projects/STSI/MedConf/QRViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/ConfListTableViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/DiscussionBoard.swift /Users/satre/Developer/Projects/STSI/MedConf/ENSideMenu.swift /Users/satre/Developer/Projects/STSI/MedConf/Session.swift /Users/satre/Developer/Projects/STSI/MedConf/QRWebViewController.swift /Users/satre/Developer/Projects/STSI/MedConf/ManTabBarController.swift /Users/satre/Developer/Projects/STSI/MedConf/ObjectManager.swift /Users/satre/Developer/Projects/STSI/MedConf/ColoredSegmentButton.swift /Users/satre/Developer/Projects/STSI/MedConf/DBManager.swift /Users/satre/Developer/Projects/STSI/MedConf/ENSideMenuNavigationController.swift -target x86_64-apple-ios8.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk -I /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Products/Debug-iphonesimulator -F /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Products/Debug-iphonesimulator -F /Users/satre/Developer/Projects/STSI -F /Users/satre/Developer/Projects/STSI/MedConf -F /Users/satre/Downloads/parse-library-1 -enable-testing -g -import-objc-header /Users/satre/Developer/Projects/STSI/MedConf-Bridging-Header.h -module-cache-path /Users/satre/Library/Developer/Xcode/DerivedData/ModuleCache -D COCOAPODS -serialize-debugging-options -Xcc -I/Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/STSI-generated-files.hmap -Xcc -I/Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/STSI-own-target-headers.hmap -Xcc -I/Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/STSI-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/STSI-project-headers.hmap -Xcc -I/Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/DerivedSources/x86_64 -Xcc -I/Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -DCOCOAPODS=1 -Xcc -working-directory/Users/satre/Developer/Projects/STSI -emit-module-doc-path /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/Objects-normal/x86_64/Event~partial.swiftdoc -Onone -module-name STSI -emit-module-path /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/Objects-normal/x86_64/Event~partial.swiftmodule -serialize-diagnostics-path /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/Objects-normal/x86_64/Event.dia -emit-dependencies-path /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/Objects-normal/x86_64/Event.d -emit-reference-dependencies-path /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/Objects-normal/x86_64/Event.swiftdeps -o /Users/satre/Library/Developer/Xcode/DerivedData/STSI-gpjzpccyzlbzmdciwcbqdfguddto/Build/Intermediates/STSI.build/Debug-iphonesimulator/STSI.build/Objects-normal/x86_64/Event.o 1. While type-checking 'fetchSpeakersForEvent' at /Users/satre/Developer/Projects/STSI/MedConf/Event.swift:220:5 2. While type-checking expression at [/Users/satre/Developer/Projects/STSI/MedConf/Event.swift:228:9 - line:256:10] RangeText="query?.findObjectsInBackgroundWithBlock({ (speakerObjects:[AnyObject]?, error:NSError?) -> Void in if error != nil { print( error ) return } let theSpeakers: [Speaker] = speakerObjects!.map({ (aSpeaker: AnyObject) -> Speaker in let theSpeaker = aSpeaker as! Speaker //Don't want to hog up the main thread, so dispatch to queue dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { () -> Void in for someSpeaker in ObjectManager.speakers { if someSpeaker.objectId == theSpeaker.objectId { if !someSpeaker.eventsForSpeaker.contains(self) { someSpeaker.eventsForSpeaker.append(self) } } } NSNotificationCenter.defaultCenter().postNotificationName(DataConstants.newSpeakerEventRelationships, object: nil) }) return theSpeaker }) self.speakersForEvent = theSpeakers })" 3. While type-checking expression at [/Users/satre/Developer/Projects/STSI/MedConf/Event.swift:228:9 - line:256:10] RangeText="query?.findObjectsInBackgroundWithBlock({ (speakerObjects:[AnyObject]?, error:NSError?) -> Void in if error != nil { print( error ) return } let theSpeakers: [Speaker] = speakerObjects!.map({ (aSpeaker: AnyObject) -> Speaker in let theSpeaker = aSpeaker as! Speaker //Don't want to hog up the main thread, so dispatch to queue dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { () -> Void in for someSpeaker in ObjectManager.speakers { if someSpeaker.objectId == theSpeaker.objectId { if !someSpeaker.eventsForSpeaker.contains(self) { someSpeaker.eventsForSpeaker.append(self) } } } NSNotificationCenter.defaultCenter().postNotificationName(DataConstants.newSpeakerEventRelationships, object: nil) }) return theSpeaker }) self.speakersForEvent = theSpeakers })" 4. While type-checking expression at [/Users/satre/Developer/Projects/STSI/MedConf/Event.swift:228:9 - line:256:10] RangeText="query?.findObjectsInBackgroundWithBlock({ (speakerObjects:[AnyObject]?, error:NSError?) -> Void in if error != nil { print( error ) return } let theSpeakers: [Speaker] = speakerObjects!.map({ (aSpeaker: AnyObject) -> Speaker in let theSpeaker = aSpeaker as! Speaker //Don't want to hog up the main thread, so dispatch to queue dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { () -> Void in for someSpeaker in ObjectManager.speakers { if someSpeaker.objectId == theSpeaker.objectId { if !someSpeaker.eventsForSpeaker.contains(self) { someSpeaker.eventsForSpeaker.append(self) } } } NSNotificationCenter.defaultCenter().postNotificationName(DataConstants.newSpeakerEventRelationships, object: nil) }) return theSpeaker }) self.speakersForEvent = theSpeakers })" 5. While type-checking expression at [/Users/satre/Developer/Projects/STSI/MedConf/Event.swift:228:49 - line:256:9] RangeText="{ (speakerObjects:[AnyObject]?, error:NSError?) -> Void in if error != nil { print( error ) return } let theSpeakers: [Speaker] = speakerObjects!.map({ (aSpeaker: AnyObject) -> Speaker in let theSpeaker = aSpeaker as! Speaker //Don't want to hog up the main thread, so dispatch to queue dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { () -> Void in for someSpeaker in ObjectManager.speakers { if someSpeaker.objectId == theSpeaker.objectId { if !someSpeaker.eventsForSpeaker.contains(self) { someSpeaker.eventsForSpeaker.append(self) } } } NSNotificationCenter.defaultCenter().postNotificationName(DataConstants.newSpeakerEventRelationships, object: nil) }) return theSpeaker }) self.speakersForEvent = theSpeakers }" 大小时,向量显然填充了垃圾内存,它显示:n,当我尝试时代码崩溃使用矢量。

0x23fe20

2 个答案:

答案 0 :(得分:4)

你正在表达cout&lt;&lt; vec以某种方式漂亮打印矢量。它不会,它只是打印其地址

您需要遍历内容并打印每个元素

for(int i =0 ; i < 10 ; i++)
{
   cout << vec[i];
}

答案 1 :(得分:1)

以下是使用现代C ++的外观:

#include <iostream>
#include <vector>

using namespace std;

void cargavn(vector<int> &vec)
{
    int t;       
    cout << "vector size: ";
    cin >> t;
    for(int i = 0; t > 0; ++i, --t)
    {
        cout << "v["<< i <<"]=";
        int v;
        cin >> v;
        vec.push_back(v);
    }
}

ostream &operator<<(ostream &s, vector<int> const &vec)
{
    s << '{';
    bool first = true;
    for (int v : vec)
    {
        if (!first)
        {
            s << ", ";
        }
        s << v;
        first = false;
    }
    return s << '}';
}

int main()
{
    vector<int> vec;
    cargavn(vec);
    cout << vec;
    system("PAUSE");
    return 0;
}

与您的版本相比,该版本需要了解的事项:

  • 不必要的包括在内。
  • 首选C ++容器,如vector,而不是C样式数组。
  • 当需要保存用户提供的任意数量的值而不是当用户输入过多数据时中断的固定大小容器时,使用动态大小的容器。请参阅rule of 0, 1, infinity
  • 当函数的所有控制路径返回相同的值时,返回的值是没有意义的,可以省略。特别是如果没有一个呼叫者甚至不愿意检查返回值。我怀疑你有意使用返回值来表示某种意外错误。这是一种C风格的错误处理方法。 C ++使用异常来处理意外错误。
  • 重载operator<<以扩展流插入运算符,以决定应如何格式化容器和您自己的自定义类型。标准库没有为vector提供任何此类插入运算符,因为没有任何普遍认可的方法来决定如何格式化值向量。所以你自己决定这个。
  • main返回值是一种很好的形式,即使这在技术上并不需要。