C++ std::array reimplementation [closed]

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
-1
down vote
favorite
As a conceptual implementation of the default c++ std array interface, would this be a suitable implementation & what is the safety of this implementation?
template<typename T>
class Array
private:
T* arr;
public:
Array(const size_t size)
arr = (T*)malloc(sizeof(T) * size);
~Array()
free(arr);
T& operator(size_t index) const
return arr[index];
;
c++ array
closed as off-topic by Incomputable, Stephen Rauch, JDÃ
Âugosz, Billal BEGUERADJ, Raystafarian Jun 11 at 4:14
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â Incomputable, JDÃ Âugosz, Billal BEGUERADJ, Raystafarian
add a comment |Â
up vote
-1
down vote
favorite
As a conceptual implementation of the default c++ std array interface, would this be a suitable implementation & what is the safety of this implementation?
template<typename T>
class Array
private:
T* arr;
public:
Array(const size_t size)
arr = (T*)malloc(sizeof(T) * size);
~Array()
free(arr);
T& operator(size_t index) const
return arr[index];
;
c++ array
closed as off-topic by Incomputable, Stephen Rauch, JDÃ
Âugosz, Billal BEGUERADJ, Raystafarian Jun 11 at 4:14
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â Incomputable, JDÃ Âugosz, Billal BEGUERADJ, Raystafarian
ThereâÂÂs an issue here also ifTrequires initialization (i.e. itâÂÂs something different from a numeric type).
â Cris Luengo
Jun 11 at 1:07
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
As a conceptual implementation of the default c++ std array interface, would this be a suitable implementation & what is the safety of this implementation?
template<typename T>
class Array
private:
T* arr;
public:
Array(const size_t size)
arr = (T*)malloc(sizeof(T) * size);
~Array()
free(arr);
T& operator(size_t index) const
return arr[index];
;
c++ array
As a conceptual implementation of the default c++ std array interface, would this be a suitable implementation & what is the safety of this implementation?
template<typename T>
class Array
private:
T* arr;
public:
Array(const size_t size)
arr = (T*)malloc(sizeof(T) * size);
~Array()
free(arr);
T& operator(size_t index) const
return arr[index];
;
c++ array
asked Jun 10 at 23:10
James
1
1
closed as off-topic by Incomputable, Stephen Rauch, JDÃ
Âugosz, Billal BEGUERADJ, Raystafarian Jun 11 at 4:14
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â Incomputable, JDÃ Âugosz, Billal BEGUERADJ, Raystafarian
closed as off-topic by Incomputable, Stephen Rauch, JDÃ
Âugosz, Billal BEGUERADJ, Raystafarian Jun 11 at 4:14
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." â Incomputable, JDÃ Âugosz, Billal BEGUERADJ, Raystafarian
ThereâÂÂs an issue here also ifTrequires initialization (i.e. itâÂÂs something different from a numeric type).
â Cris Luengo
Jun 11 at 1:07
add a comment |Â
ThereâÂÂs an issue here also ifTrequires initialization (i.e. itâÂÂs something different from a numeric type).
â Cris Luengo
Jun 11 at 1:07
ThereâÂÂs an issue here also if
T requires initialization (i.e. itâÂÂs something different from a numeric type).â Cris Luengo
Jun 11 at 1:07
ThereâÂÂs an issue here also if
T requires initialization (i.e. itâÂÂs something different from a numeric type).â Cris Luengo
Jun 11 at 1:07
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
The code you provided is more like a vector rather than an array. An array's size is specified at compile-time (is fixed). Hence the most basic implementation would be:
#include <cstddef>
template<typename type, std::size_t size>
struct array
type data[size];
;
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
The code you provided is more like a vector rather than an array. An array's size is specified at compile-time (is fixed). Hence the most basic implementation would be:
#include <cstddef>
template<typename type, std::size_t size>
struct array
type data[size];
;
add a comment |Â
up vote
1
down vote
The code you provided is more like a vector rather than an array. An array's size is specified at compile-time (is fixed). Hence the most basic implementation would be:
#include <cstddef>
template<typename type, std::size_t size>
struct array
type data[size];
;
add a comment |Â
up vote
1
down vote
up vote
1
down vote
The code you provided is more like a vector rather than an array. An array's size is specified at compile-time (is fixed). Hence the most basic implementation would be:
#include <cstddef>
template<typename type, std::size_t size>
struct array
type data[size];
;
The code you provided is more like a vector rather than an array. An array's size is specified at compile-time (is fixed). Hence the most basic implementation would be:
#include <cstddef>
template<typename type, std::size_t size>
struct array
type data[size];
;
answered Jun 11 at 0:25
demiralp
436
436
add a comment |Â
add a comment |Â
ThereâÂÂs an issue here also if
Trequires initialization (i.e. itâÂÂs something different from a numeric type).â Cris Luengo
Jun 11 at 1:07