I am getting a C++ error saying saying my class constructor argument types don't match my parameter types










0














Here is my constructor code:



vertex_array(float* &vertex_buffer, std::string& texture_file);


Here is my main application code:



float cube1 = 0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,

0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f ;

vertex_array va_1(cube1, "blocks.png");


I am getting the error: no instance of constructor "vertex_array::vertex_array" matches the argument list argument types are: (float[40], const char[11])



I have spent around an hour looking for the problem yet I cannot find anything wrong with the code. I even looked at another example that passed in the exact same argument type but to a parameter of type const void* and it worked on the example however not for me. What is my problem?










share|improve this question

















  • 2




    float* & - Why?
    – Jesper Juhl
    Nov 11 '18 at 14:31










  • As @JesperJuhl mentions, it looks like your constructor interface is expecting an output parameter that you are passing an array to and not a pointer to the array.
    – Bo R
    Nov 11 '18 at 14:35






  • 1




    Also, you want const std::string& texture_file
    – Neil Butterworth
    Nov 11 '18 at 14:39










  • Jesper Juhl and Bo R, the parameter type is float* & because I will be passing in a pointer to a float array and im pretty sure the array name is a pointer to the first index of an array which is what I pass in and then I make it a reference because I dont want it to be copied
    – adamtheguy762
    Nov 11 '18 at 15:56















0














Here is my constructor code:



vertex_array(float* &vertex_buffer, std::string& texture_file);


Here is my main application code:



float cube1 = 0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,

0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f ;

vertex_array va_1(cube1, "blocks.png");


I am getting the error: no instance of constructor "vertex_array::vertex_array" matches the argument list argument types are: (float[40], const char[11])



I have spent around an hour looking for the problem yet I cannot find anything wrong with the code. I even looked at another example that passed in the exact same argument type but to a parameter of type const void* and it worked on the example however not for me. What is my problem?










share|improve this question

















  • 2




    float* & - Why?
    – Jesper Juhl
    Nov 11 '18 at 14:31










  • As @JesperJuhl mentions, it looks like your constructor interface is expecting an output parameter that you are passing an array to and not a pointer to the array.
    – Bo R
    Nov 11 '18 at 14:35






  • 1




    Also, you want const std::string& texture_file
    – Neil Butterworth
    Nov 11 '18 at 14:39










  • Jesper Juhl and Bo R, the parameter type is float* & because I will be passing in a pointer to a float array and im pretty sure the array name is a pointer to the first index of an array which is what I pass in and then I make it a reference because I dont want it to be copied
    – adamtheguy762
    Nov 11 '18 at 15:56













0












0








0







Here is my constructor code:



vertex_array(float* &vertex_buffer, std::string& texture_file);


Here is my main application code:



float cube1 = 0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,

0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f ;

vertex_array va_1(cube1, "blocks.png");


I am getting the error: no instance of constructor "vertex_array::vertex_array" matches the argument list argument types are: (float[40], const char[11])



I have spent around an hour looking for the problem yet I cannot find anything wrong with the code. I even looked at another example that passed in the exact same argument type but to a parameter of type const void* and it worked on the example however not for me. What is my problem?










share|improve this question













Here is my constructor code:



vertex_array(float* &vertex_buffer, std::string& texture_file);


Here is my main application code:



float cube1 = 0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,

0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f ;

vertex_array va_1(cube1, "blocks.png");


I am getting the error: no instance of constructor "vertex_array::vertex_array" matches the argument list argument types are: (float[40], const char[11])



I have spent around an hour looking for the problem yet I cannot find anything wrong with the code. I even looked at another example that passed in the exact same argument type but to a parameter of type const void* and it worked on the example however not for me. What is my problem?







c++ types parameters constructor arguments






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 '18 at 14:25









adamtheguy762

33




33







  • 2




    float* & - Why?
    – Jesper Juhl
    Nov 11 '18 at 14:31










  • As @JesperJuhl mentions, it looks like your constructor interface is expecting an output parameter that you are passing an array to and not a pointer to the array.
    – Bo R
    Nov 11 '18 at 14:35






  • 1




    Also, you want const std::string& texture_file
    – Neil Butterworth
    Nov 11 '18 at 14:39










  • Jesper Juhl and Bo R, the parameter type is float* & because I will be passing in a pointer to a float array and im pretty sure the array name is a pointer to the first index of an array which is what I pass in and then I make it a reference because I dont want it to be copied
    – adamtheguy762
    Nov 11 '18 at 15:56












  • 2




    float* & - Why?
    – Jesper Juhl
    Nov 11 '18 at 14:31










  • As @JesperJuhl mentions, it looks like your constructor interface is expecting an output parameter that you are passing an array to and not a pointer to the array.
    – Bo R
    Nov 11 '18 at 14:35






  • 1




    Also, you want const std::string& texture_file
    – Neil Butterworth
    Nov 11 '18 at 14:39










  • Jesper Juhl and Bo R, the parameter type is float* & because I will be passing in a pointer to a float array and im pretty sure the array name is a pointer to the first index of an array which is what I pass in and then I make it a reference because I dont want it to be copied
    – adamtheguy762
    Nov 11 '18 at 15:56







2




2




float* & - Why?
– Jesper Juhl
Nov 11 '18 at 14:31




float* & - Why?
– Jesper Juhl
Nov 11 '18 at 14:31












As @JesperJuhl mentions, it looks like your constructor interface is expecting an output parameter that you are passing an array to and not a pointer to the array.
– Bo R
Nov 11 '18 at 14:35




As @JesperJuhl mentions, it looks like your constructor interface is expecting an output parameter that you are passing an array to and not a pointer to the array.
– Bo R
Nov 11 '18 at 14:35




1




1




Also, you want const std::string& texture_file
– Neil Butterworth
Nov 11 '18 at 14:39




Also, you want const std::string& texture_file
– Neil Butterworth
Nov 11 '18 at 14:39












Jesper Juhl and Bo R, the parameter type is float* & because I will be passing in a pointer to a float array and im pretty sure the array name is a pointer to the first index of an array which is what I pass in and then I make it a reference because I dont want it to be copied
– adamtheguy762
Nov 11 '18 at 15:56




Jesper Juhl and Bo R, the parameter type is float* & because I will be passing in a pointer to a float array and im pretty sure the array name is a pointer to the first index of an array which is what I pass in and then I make it a reference because I dont want it to be copied
– adamtheguy762
Nov 11 '18 at 15:56












2 Answers
2






active

oldest

votes


















0














The first argument you give to the constructor is a pointer to a number of floats and the second is a const char* which will be implicitly converted to a const std::string, so you need to change the signature accordingly:



vertex_array(float* vertex_buffer, const std::string& texture_file);


You could also remove the reference declaration for texture_file to make it valid but if you are later going to instantiate a vertex_array using a real std::string, it would result in an unnecessary copy construction, so go for the const reference.



If you have different sizes of vertex_buffers, you need to supply the size as an argument too or consider using std::initializer_list or a container to keep track of the number of elements.



Example:



vertex_array(std::initializer_list<float> vertex_buffer, const std::string& texture_file);

vertex_array va_2(
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,

0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, "blocks.png");





share|improve this answer






















  • Ok thanks for your suggestion it has fixed my error however I still dont fully understand what your saying about why my code didnt work. So firstly, why cant I take a reference to the array? And secondly, why must the string be const? I think you might have explained this already however I didnt fully understand your explanation e.g. "you could also remove the reference declaration for texture_file to make it valid", why wasnt it previously valid?
    – adamtheguy762
    Nov 11 '18 at 16:07










  • No, when you pass a C-style array as an argument it'll decay to a pointer to the first element, so you'll loose the size info. I you'd like size information to be preserved, it's easier using a C++ container or initializer_list. "blocks.png" is a const char*. The constness will be preserved when implicitly converted to const std::string which is why you can't receive it as a std::string&. It would cast away constness.
    – Ted Lyngmo
    Nov 11 '18 at 16:22











  • Ok so I have added a size variable but will the rest of the arrays indexes still be accessable within the constructor? Also I would prefer not to use the initializer_list or container because I am unfamiliar with them and would prefer my code ot consist of code I am familiar with.
    – adamtheguy762
    Nov 11 '18 at 17:49










  • Also, why is "blocks.png" an const char*? I didnt give it any type it is just a string in my eyes.
    – adamtheguy762
    Nov 11 '18 at 17:50










  • I'm not sure I understand what you mean by the rest of the arrays indexes. You have a pointer to the first float and probably a size_t for the number of elements. That's all you get and all you need. Check out number 1 at string literal describing the types of literal strings.
    – Ted Lyngmo
    Nov 11 '18 at 17:56



















-2














I think you may be using your address of operators & incorrectly.



Remove Them both from the declaration and try again.



Using them for the array is pointless and literally cancels out what you are trying to achieve. The second argument is also incorrect because you are trying to get the address of an r-value.






share|improve this answer


















  • 1




    This is not the "address of" operator. It's a reference declaration.
    – Geier
    Nov 11 '18 at 14:44






  • 1




    Correcting an error is not "trolling", and is exactly what SO is all about.
    – Neil Butterworth
    Nov 11 '18 at 14:55











  • well in that case I would like to correct both of your opinions. Take this article for example. quora.com/…
    – mreff555
    Nov 11 '18 at 14:58










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249670%2fi-am-getting-a-c-error-saying-saying-my-class-constructor-argument-types-dont%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The first argument you give to the constructor is a pointer to a number of floats and the second is a const char* which will be implicitly converted to a const std::string, so you need to change the signature accordingly:



vertex_array(float* vertex_buffer, const std::string& texture_file);


You could also remove the reference declaration for texture_file to make it valid but if you are later going to instantiate a vertex_array using a real std::string, it would result in an unnecessary copy construction, so go for the const reference.



If you have different sizes of vertex_buffers, you need to supply the size as an argument too or consider using std::initializer_list or a container to keep track of the number of elements.



Example:



vertex_array(std::initializer_list<float> vertex_buffer, const std::string& texture_file);

vertex_array va_2(
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,

0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, "blocks.png");





share|improve this answer






















  • Ok thanks for your suggestion it has fixed my error however I still dont fully understand what your saying about why my code didnt work. So firstly, why cant I take a reference to the array? And secondly, why must the string be const? I think you might have explained this already however I didnt fully understand your explanation e.g. "you could also remove the reference declaration for texture_file to make it valid", why wasnt it previously valid?
    – adamtheguy762
    Nov 11 '18 at 16:07










  • No, when you pass a C-style array as an argument it'll decay to a pointer to the first element, so you'll loose the size info. I you'd like size information to be preserved, it's easier using a C++ container or initializer_list. "blocks.png" is a const char*. The constness will be preserved when implicitly converted to const std::string which is why you can't receive it as a std::string&. It would cast away constness.
    – Ted Lyngmo
    Nov 11 '18 at 16:22











  • Ok so I have added a size variable but will the rest of the arrays indexes still be accessable within the constructor? Also I would prefer not to use the initializer_list or container because I am unfamiliar with them and would prefer my code ot consist of code I am familiar with.
    – adamtheguy762
    Nov 11 '18 at 17:49










  • Also, why is "blocks.png" an const char*? I didnt give it any type it is just a string in my eyes.
    – adamtheguy762
    Nov 11 '18 at 17:50










  • I'm not sure I understand what you mean by the rest of the arrays indexes. You have a pointer to the first float and probably a size_t for the number of elements. That's all you get and all you need. Check out number 1 at string literal describing the types of literal strings.
    – Ted Lyngmo
    Nov 11 '18 at 17:56
















0














The first argument you give to the constructor is a pointer to a number of floats and the second is a const char* which will be implicitly converted to a const std::string, so you need to change the signature accordingly:



vertex_array(float* vertex_buffer, const std::string& texture_file);


You could also remove the reference declaration for texture_file to make it valid but if you are later going to instantiate a vertex_array using a real std::string, it would result in an unnecessary copy construction, so go for the const reference.



If you have different sizes of vertex_buffers, you need to supply the size as an argument too or consider using std::initializer_list or a container to keep track of the number of elements.



Example:



vertex_array(std::initializer_list<float> vertex_buffer, const std::string& texture_file);

vertex_array va_2(
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,

0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, "blocks.png");





share|improve this answer






















  • Ok thanks for your suggestion it has fixed my error however I still dont fully understand what your saying about why my code didnt work. So firstly, why cant I take a reference to the array? And secondly, why must the string be const? I think you might have explained this already however I didnt fully understand your explanation e.g. "you could also remove the reference declaration for texture_file to make it valid", why wasnt it previously valid?
    – adamtheguy762
    Nov 11 '18 at 16:07










  • No, when you pass a C-style array as an argument it'll decay to a pointer to the first element, so you'll loose the size info. I you'd like size information to be preserved, it's easier using a C++ container or initializer_list. "blocks.png" is a const char*. The constness will be preserved when implicitly converted to const std::string which is why you can't receive it as a std::string&. It would cast away constness.
    – Ted Lyngmo
    Nov 11 '18 at 16:22











  • Ok so I have added a size variable but will the rest of the arrays indexes still be accessable within the constructor? Also I would prefer not to use the initializer_list or container because I am unfamiliar with them and would prefer my code ot consist of code I am familiar with.
    – adamtheguy762
    Nov 11 '18 at 17:49










  • Also, why is "blocks.png" an const char*? I didnt give it any type it is just a string in my eyes.
    – adamtheguy762
    Nov 11 '18 at 17:50










  • I'm not sure I understand what you mean by the rest of the arrays indexes. You have a pointer to the first float and probably a size_t for the number of elements. That's all you get and all you need. Check out number 1 at string literal describing the types of literal strings.
    – Ted Lyngmo
    Nov 11 '18 at 17:56














0












0








0






The first argument you give to the constructor is a pointer to a number of floats and the second is a const char* which will be implicitly converted to a const std::string, so you need to change the signature accordingly:



vertex_array(float* vertex_buffer, const std::string& texture_file);


You could also remove the reference declaration for texture_file to make it valid but if you are later going to instantiate a vertex_array using a real std::string, it would result in an unnecessary copy construction, so go for the const reference.



If you have different sizes of vertex_buffers, you need to supply the size as an argument too or consider using std::initializer_list or a container to keep track of the number of elements.



Example:



vertex_array(std::initializer_list<float> vertex_buffer, const std::string& texture_file);

vertex_array va_2(
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,

0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, "blocks.png");





share|improve this answer














The first argument you give to the constructor is a pointer to a number of floats and the second is a const char* which will be implicitly converted to a const std::string, so you need to change the signature accordingly:



vertex_array(float* vertex_buffer, const std::string& texture_file);


You could also remove the reference declaration for texture_file to make it valid but if you are later going to instantiate a vertex_array using a real std::string, it would result in an unnecessary copy construction, so go for the const reference.



If you have different sizes of vertex_buffers, you need to supply the size as an argument too or consider using std::initializer_list or a container to keep track of the number of elements.



Example:



vertex_array(std::initializer_list<float> vertex_buffer, const std::string& texture_file);

vertex_array va_2(
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,

0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, "blocks.png");






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 '18 at 19:13

























answered Nov 11 '18 at 15:35









Ted Lyngmo

1,9891315




1,9891315











  • Ok thanks for your suggestion it has fixed my error however I still dont fully understand what your saying about why my code didnt work. So firstly, why cant I take a reference to the array? And secondly, why must the string be const? I think you might have explained this already however I didnt fully understand your explanation e.g. "you could also remove the reference declaration for texture_file to make it valid", why wasnt it previously valid?
    – adamtheguy762
    Nov 11 '18 at 16:07










  • No, when you pass a C-style array as an argument it'll decay to a pointer to the first element, so you'll loose the size info. I you'd like size information to be preserved, it's easier using a C++ container or initializer_list. "blocks.png" is a const char*. The constness will be preserved when implicitly converted to const std::string which is why you can't receive it as a std::string&. It would cast away constness.
    – Ted Lyngmo
    Nov 11 '18 at 16:22











  • Ok so I have added a size variable but will the rest of the arrays indexes still be accessable within the constructor? Also I would prefer not to use the initializer_list or container because I am unfamiliar with them and would prefer my code ot consist of code I am familiar with.
    – adamtheguy762
    Nov 11 '18 at 17:49










  • Also, why is "blocks.png" an const char*? I didnt give it any type it is just a string in my eyes.
    – adamtheguy762
    Nov 11 '18 at 17:50










  • I'm not sure I understand what you mean by the rest of the arrays indexes. You have a pointer to the first float and probably a size_t for the number of elements. That's all you get and all you need. Check out number 1 at string literal describing the types of literal strings.
    – Ted Lyngmo
    Nov 11 '18 at 17:56

















  • Ok thanks for your suggestion it has fixed my error however I still dont fully understand what your saying about why my code didnt work. So firstly, why cant I take a reference to the array? And secondly, why must the string be const? I think you might have explained this already however I didnt fully understand your explanation e.g. "you could also remove the reference declaration for texture_file to make it valid", why wasnt it previously valid?
    – adamtheguy762
    Nov 11 '18 at 16:07










  • No, when you pass a C-style array as an argument it'll decay to a pointer to the first element, so you'll loose the size info. I you'd like size information to be preserved, it's easier using a C++ container or initializer_list. "blocks.png" is a const char*. The constness will be preserved when implicitly converted to const std::string which is why you can't receive it as a std::string&. It would cast away constness.
    – Ted Lyngmo
    Nov 11 '18 at 16:22











  • Ok so I have added a size variable but will the rest of the arrays indexes still be accessable within the constructor? Also I would prefer not to use the initializer_list or container because I am unfamiliar with them and would prefer my code ot consist of code I am familiar with.
    – adamtheguy762
    Nov 11 '18 at 17:49










  • Also, why is "blocks.png" an const char*? I didnt give it any type it is just a string in my eyes.
    – adamtheguy762
    Nov 11 '18 at 17:50










  • I'm not sure I understand what you mean by the rest of the arrays indexes. You have a pointer to the first float and probably a size_t for the number of elements. That's all you get and all you need. Check out number 1 at string literal describing the types of literal strings.
    – Ted Lyngmo
    Nov 11 '18 at 17:56
















Ok thanks for your suggestion it has fixed my error however I still dont fully understand what your saying about why my code didnt work. So firstly, why cant I take a reference to the array? And secondly, why must the string be const? I think you might have explained this already however I didnt fully understand your explanation e.g. "you could also remove the reference declaration for texture_file to make it valid", why wasnt it previously valid?
– adamtheguy762
Nov 11 '18 at 16:07




Ok thanks for your suggestion it has fixed my error however I still dont fully understand what your saying about why my code didnt work. So firstly, why cant I take a reference to the array? And secondly, why must the string be const? I think you might have explained this already however I didnt fully understand your explanation e.g. "you could also remove the reference declaration for texture_file to make it valid", why wasnt it previously valid?
– adamtheguy762
Nov 11 '18 at 16:07












No, when you pass a C-style array as an argument it'll decay to a pointer to the first element, so you'll loose the size info. I you'd like size information to be preserved, it's easier using a C++ container or initializer_list. "blocks.png" is a const char*. The constness will be preserved when implicitly converted to const std::string which is why you can't receive it as a std::string&. It would cast away constness.
– Ted Lyngmo
Nov 11 '18 at 16:22





No, when you pass a C-style array as an argument it'll decay to a pointer to the first element, so you'll loose the size info. I you'd like size information to be preserved, it's easier using a C++ container or initializer_list. "blocks.png" is a const char*. The constness will be preserved when implicitly converted to const std::string which is why you can't receive it as a std::string&. It would cast away constness.
– Ted Lyngmo
Nov 11 '18 at 16:22













Ok so I have added a size variable but will the rest of the arrays indexes still be accessable within the constructor? Also I would prefer not to use the initializer_list or container because I am unfamiliar with them and would prefer my code ot consist of code I am familiar with.
– adamtheguy762
Nov 11 '18 at 17:49




Ok so I have added a size variable but will the rest of the arrays indexes still be accessable within the constructor? Also I would prefer not to use the initializer_list or container because I am unfamiliar with them and would prefer my code ot consist of code I am familiar with.
– adamtheguy762
Nov 11 '18 at 17:49












Also, why is "blocks.png" an const char*? I didnt give it any type it is just a string in my eyes.
– adamtheguy762
Nov 11 '18 at 17:50




Also, why is "blocks.png" an const char*? I didnt give it any type it is just a string in my eyes.
– adamtheguy762
Nov 11 '18 at 17:50












I'm not sure I understand what you mean by the rest of the arrays indexes. You have a pointer to the first float and probably a size_t for the number of elements. That's all you get and all you need. Check out number 1 at string literal describing the types of literal strings.
– Ted Lyngmo
Nov 11 '18 at 17:56





I'm not sure I understand what you mean by the rest of the arrays indexes. You have a pointer to the first float and probably a size_t for the number of elements. That's all you get and all you need. Check out number 1 at string literal describing the types of literal strings.
– Ted Lyngmo
Nov 11 '18 at 17:56














-2














I think you may be using your address of operators & incorrectly.



Remove Them both from the declaration and try again.



Using them for the array is pointless and literally cancels out what you are trying to achieve. The second argument is also incorrect because you are trying to get the address of an r-value.






share|improve this answer


















  • 1




    This is not the "address of" operator. It's a reference declaration.
    – Geier
    Nov 11 '18 at 14:44






  • 1




    Correcting an error is not "trolling", and is exactly what SO is all about.
    – Neil Butterworth
    Nov 11 '18 at 14:55











  • well in that case I would like to correct both of your opinions. Take this article for example. quora.com/…
    – mreff555
    Nov 11 '18 at 14:58















-2














I think you may be using your address of operators & incorrectly.



Remove Them both from the declaration and try again.



Using them for the array is pointless and literally cancels out what you are trying to achieve. The second argument is also incorrect because you are trying to get the address of an r-value.






share|improve this answer


















  • 1




    This is not the "address of" operator. It's a reference declaration.
    – Geier
    Nov 11 '18 at 14:44






  • 1




    Correcting an error is not "trolling", and is exactly what SO is all about.
    – Neil Butterworth
    Nov 11 '18 at 14:55











  • well in that case I would like to correct both of your opinions. Take this article for example. quora.com/…
    – mreff555
    Nov 11 '18 at 14:58













-2












-2








-2






I think you may be using your address of operators & incorrectly.



Remove Them both from the declaration and try again.



Using them for the array is pointless and literally cancels out what you are trying to achieve. The second argument is also incorrect because you are trying to get the address of an r-value.






share|improve this answer














I think you may be using your address of operators & incorrectly.



Remove Them both from the declaration and try again.



Using them for the array is pointless and literally cancels out what you are trying to achieve. The second argument is also incorrect because you are trying to get the address of an r-value.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 '18 at 15:58









Hovercraft Full Of Eels

261k20211317




261k20211317










answered Nov 11 '18 at 14:41









mreff555

470212




470212







  • 1




    This is not the "address of" operator. It's a reference declaration.
    – Geier
    Nov 11 '18 at 14:44






  • 1




    Correcting an error is not "trolling", and is exactly what SO is all about.
    – Neil Butterworth
    Nov 11 '18 at 14:55











  • well in that case I would like to correct both of your opinions. Take this article for example. quora.com/…
    – mreff555
    Nov 11 '18 at 14:58












  • 1




    This is not the "address of" operator. It's a reference declaration.
    – Geier
    Nov 11 '18 at 14:44






  • 1




    Correcting an error is not "trolling", and is exactly what SO is all about.
    – Neil Butterworth
    Nov 11 '18 at 14:55











  • well in that case I would like to correct both of your opinions. Take this article for example. quora.com/…
    – mreff555
    Nov 11 '18 at 14:58







1




1




This is not the "address of" operator. It's a reference declaration.
– Geier
Nov 11 '18 at 14:44




This is not the "address of" operator. It's a reference declaration.
– Geier
Nov 11 '18 at 14:44




1




1




Correcting an error is not "trolling", and is exactly what SO is all about.
– Neil Butterworth
Nov 11 '18 at 14:55





Correcting an error is not "trolling", and is exactly what SO is all about.
– Neil Butterworth
Nov 11 '18 at 14:55













well in that case I would like to correct both of your opinions. Take this article for example. quora.com/…
– mreff555
Nov 11 '18 at 14:58




well in that case I would like to correct both of your opinions. Take this article for example. quora.com/…
– mreff555
Nov 11 '18 at 14:58

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249670%2fi-am-getting-a-c-error-saying-saying-my-class-constructor-argument-types-dont%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo