Jump to content
  • Advertisement
Sign in to follow this  
supagu

stupid q'n: 2d char array

This topic is 5460 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

what i have is a 2d array of chars: char buffer[6][256] 6 strings to file names now when i pass this string to a function with prototype: const char* file[] it spits chips saying: cant convert from char*[6] to const char*[] whats up with this?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by supagu
what i have is a 2d array of chars:

char buffer[6][256]

6 strings to file names

now when i pass this string to a function with prototype:
const char* file[]

it spits chips saying:
cant convert from char*[6] to const char*[]

whats up with this?



You need to specify the size of the second dimension, otherwise it doesn't know how much memory to skip between the first dimensions index


EDIT: this should work, prototype with char [][256]

Share this post


Link to post
Share on other sites
Yes, you can't pass in some non-const array to a function expecting a const array. The function could be depending on the array's constness for correctness.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
Yes, you can't pass in some non-const array to a function expecting a const array. The function could be depending on the array's constness for correctness.

That's not true. You can always safely pass an instance of a pointer or reference to a type where the parameters specify some form of further cv-qualification of the referenced type. As long as you are adding qualifiers and not removing any then it is perfectly valid. You should not be getting a syntax error nor a runtime error and the functionality is fully defined by the standard.

Share this post


Link to post
Share on other sites
Urg yes. I assumed the OP was right. You have things the right way around. Never mind.

I really hate this array vs pointer stuff in C and C++, it gets especially annoying with multi-dimensional arrays. And when C++ starts throwing in it's "const"s and "&"s into error messages, it becomes that much harder to figure out what the problem is.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!