Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9181505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:19:50+00:00 2026-06-17T18:19:50+00:00

Well I am questioning myself if there is a way to pass a vector

  • 0

Well I am questioning myself if there is a way to pass a vector directly in a parameter, with that I mean, like this:

int xPOS = 5, yPOS = 6, zPOS = 2;
//^this is actually a struct but 
//I simplified the code to this

std::vector <std::vector<int>>  NodePoints;
NodePoints.push_back(
    std::vector<int> {xPOS,yPOS,zPOS}
);

This code ofcourse gives an error; typename not allowed, and expected a ‘)’

I would have used a struct, but I have to pass the data to a Abstract Virtual Machine where I need to access the node positions as Array[index][index] like:

public GPS_WhenRouteIsCalculated(...)
{
    for(new i = 0; i < amount_of_nodes; ++i)
    {
        printf("Point(%d)=NodeID(%d), Position(X;Y;Z):{%f;%f;%f}",i,node_id_array[i],NodePosition[i][0],NodePosition[i][1],NodePosition[i][2]); 
    }
    return 1;
}

Ofcourse I could do it like this:

std::vector <std::vector<int>>  NodePoints;//global
std::vector<int> x;//local
x.push_back(xPOS);
x.push_back(yPOS);
x.push_back(zPOS);
NodePoints.push_back(x);

or this:

std::vector <std::vector<int>>  NodePoints;//global
std::vector<int> x;//global
x.push_back(xPOS);
x.push_back(yPOS);
x.push_back(zPOS);
NodePoints.push_back(x);
x.clear()

but then I’m wondering which of the two would be faster/more efficient/better?
Or is there a way to get my initial code working (first snippet)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:19:52+00:00Added an answer on June 17, 2026 at 6:19 pm

    Use C++11, or something from boost for this (also you can use simple v.push_back({1,2,3}), vector will be constructed from initializer_list).

    http://liveworkspace.org/code/m4kRJ$0

    You can use boost::assign as well, if you have no C++11.

    #include <vector>
    #include <boost/assign/list_of.hpp>
    
    using namespace boost::assign;
    
    int main()
    {
       std::vector<std::vector<int>> v;
       v.push_back(list_of(1)(2)(3));
    }
    

    http://liveworkspace.org/code/m4kRJ$5

    and of course you can use old variant

    int ptr[1,2,3];
    v.push_back(std::vector<int>(ptr, ptr + sizeof(ptr) / sizeof(*ptr));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

well i have a configuration like this in the components part of my config
Well there is enough information about this subject. For example this thread was very
Well my situation is like this: I am generating a report as a text
well there are 3 activities say Act1 , Act2 and Act3 . in Act1
Well, I was trying to fix this program, and I keep getting the errors
Well I don't know if the title for this question is appropriate or not,
Well the situation is bit more complicated than that ! I have a question
Update: Turns out that this is a duplicate of: JSLint: Using a function before
Well I have been thinking about this for a while, ever since I was
Well lets say i have this <table class=infoBox> <tr> <td> test </td> <td> <table>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.