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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:56:13+00:00 2026-06-13T10:56:13+00:00

I have casting problem with structures in my C++ code. I use C-style casting.

  • 0

I have casting problem with structures in my C++ code. I use C-style casting. But if i try to cast using alternative name (created using typedef) i have an error. Please, look at my code.

class T
{
public:
    typedef struct kIdS* kIdN;
    typedef struct kIdS {
        int* a;
        double* b;
    }  kIdR;

    typedef struct tIdS {
        int* a;
        double* b;
        float* c;
    }  tIdR;

    int a;
    double b;
    float c;

    void F()
    {
        a = 0; 
        b = 0; 
        c = 0;
        struct kIdS A = {&a, &b};
        struct tIdS B = {&a, &b, &c};
        struct kIdS* knv[] = {&A, (struct kIdS*)&B};
        struct kIdS* knv1[] = {&A, (kIdN)&B}; //error
    }
};

The error is:

error C2440: 'initializing' : cannot convert from 'T::kIdN' to 'T::kIdS *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, 
    C-style cast or function-style cast

Why i can not use alternative name? How i can solve this problem using alternative name created by typedef?

  • 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-13T10:56:13+00:00Added an answer on June 13, 2026 at 10:56 am

    The reason for your error is in first typedef struct kIdS* kIdN you have no struct in your class that named kIdS, so C++ compiler think that you are talking about a global struct kIdS and then typedef that global struct to kIdN and in line struct kIdS* knv1[] = {&A, (kIdN)&B}; error is obvious, global struct kIdS* can’t be used instead of T::kIdS*, but I have a question from you, why you use struct X while you can simply say X??

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

Sidebar

Related Questions

I have a casting problem. I am writing a code to open all the
I have the following casting problem when my data structure sSpecificData contains a field
I have problem with casting custom event currentTarget to component. When I'm trying to
I have a problem about casting a CallableStatement to OracleCallableStatement . It gives ClassCastException
I think I have a problem with casting. $db = mysqli_connect('127.0.0.1','root','password','test'); if (! $db)
I am new to java and I have some problem on Casting. I have
I have a problem with casting a variable (see below) to a String so
I have a problem with casting from float to double when fread; fread(doublePointer,sizeofFloat,500,f); if
I have a problem with what appears to be some sort of implicit casting
I have a problem in my code which i can't understand. I want to

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.