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

  • Home
  • SEARCH
  • 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 4055766
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:44:33+00:00 2026-05-20T14:44:33+00:00

I currently have a class like this: struct Rgb { static const int NUM_CHANNELS

  • 0

I currently have a class like this:

struct Rgb
{
  static const int NUM_CHANNELS = 3;
  unsigned char channel[NUM_CHANNELS];
};

which is never instantiated but is used to determine the stride of a pointer increment.

I wanted to allow this stride to change based on some runtime information. Will something like this work?

#include <iostream>

class Rgb
{
public:
  static int* Channel;
  static void SetChannelSize(unsigned int channelSize)
  {
    Channel = new int(channelSize);
  }
};

int main()
{

  int numbers[1000];
  for(unsigned int i = 0; i < 1000; i++)
    {
    numbers[i] = i;
    }

  Rgb::SetChannelSize(3);

  Rgb* rgbNnumbers = reinterpret_cast<Rgb*>(numbers);

  for(unsigned int i = 0; i < 5; i++)
    {
    std::cout << rgbNnumbers[i] << std::endl; //error: no match for ‘operator<<’ in ‘std::cout << *(rgbNnumbers + ((unsigned int)i))’

    }

  return 0;
}

(I wasn’t sure how to step over the demo array I setup in this example to test it out).

Any comments?

  • 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-05-20T14:44:33+00:00Added an answer on May 20, 2026 at 2:44 pm

    As [i] is a compile-time operation, it will simply not work for element sizes that are not known at compile-time. You must increment the pointer yourself with arithmetic.

    But that being said, most likely you actually know the size of the element at compile-time. You are probably writing specific code for 24-bit and 32-bit (et al) pixel depths, so you should still be able to use brackets to dereference. Just organize your code to use the right class (Rgb32, Rgb565, Rgb24, etc).

    Regarding your compiler error, iostream doesn’t know how to convert a Rgb to a string, so you naturally get this error. I would suggest creating a Rgb::ToString() function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have my PHP class variables set up like this: class someThing {
I have a linked list structure: struct SomeLinkedList { const char* bar; int lots_of_interesting_stuff_in_here;
Assuming I have a class like this: class Database { public static $hostname =
I currently have a unittest.TestCase that looks like.. class test_appletrailer(unittest.TestCase): def setup(self): self.all_trailers =
I would like to add an operator to a class. I currently have a
I currently have a custom session handler class which simply builds on php's session
I have a class named Page with a private property currently called _pageData which
I have a class like this: public class Foo<T> : IEquatable<T> where T :
I have a class like this: template <class T> class bag { private: typedef
I have a class like this public abstract class BaseType<T> { public string Name

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.