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 8190495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:40:03+00:00 2026-06-07T03:40:03+00:00

I have something like this: typedef int customType[10]; And I want a function like

  • 0

I have something like this:

typedef int customType[10];

And I want a function like this

std::vector<customType*>& myFunc();

But there are some problems.

1) I need to allocate memory for every pointer to customType in the vector (do I?)
and doing

std::vector<customType*> A;
//some code to get length
for (i = 0; i < length; i++)
{
  A[i]  = new customType;
}

is wrong because of an error:

IntelliSense: a value of type "int *" cannot be assigned to an entity of type "customType*"

2) In common, is it a good way to store such data? Maybe I should make an array of 1 dimension with everything stored in one line and use something like

A[i*innerLength+j]

to access elements?

  • 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-07T03:40:05+00:00Added an answer on June 7, 2026 at 3:40 am

    I would generally recommend using something like the below and doing the array indexing yourself.

    std::vector<int> vals(row_size*col_size, 0);
    

    At really large sizes it may be better to break it up. It’s just a lot of contiguous memory to allocate in a block. “Really large” is pretty subjective, and you probably can get away with a lot larger sizes than most people would expect. Let the profiler tell you when it’s a problem.

    If you have access to C++11, then this would be another option.

    TEST(array)
    {
        typedef std::array<int,10> Foo;
        typedef std::vector<Foo> Foos;
        Foos foos(10, Foo());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple question; right now I have something like this: typedef void(*MyFunctionPointer)(int); typedef std::vector <
I have something like this: #include <iostream> namespace N { typedef std::pair<int, double> MyPair;
I have something like this: typedef int AnotherType; template <typename T> Func( T Value
I have a C++ function like int f( const std::string &s, double d );
I want to do something like this. typedef struct Test{ int value; struct Test*
I have something like this: create table account ( id int identity(1,1) primary key,
Suppose I have code something like this: #include boost/thread/mutex.hpp using boost::mutex; typedef mutex::scoped_lock lock;
I have a interface documented like this: typedef struct Tree { int a; void*
I have a typedef in an if macro, something like: #ifdef BLA_BLA typedef int
I have a list in C that is something like this: typedef struct _node

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.