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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:58:38+00:00 2026-06-11T05:58:38+00:00

#include <linux/input.h> #include <string.h> #include <gtest/gtest.h> #include <string> class Parent{ public: Parent(){ } virtual

  • 0
#include <linux/input.h>
#include <string.h>

#include <gtest/gtest.h>
#include <string>
class Parent{
public:
    Parent(){
    }
    virtual std::string GetString()
    {
        int amount = 1;
        input_event ev[amount];
        ev[0].code = BTN_9;
        ev[0].value = 1;
        char* temp = reinterprt_cast<char*>(ev);
        std::string msg(temp, sizeof(ev) * amount);
        return msg;
    }
};
class Child : public Parent
{
public:
    Child(){
    }
    virtual std::string GetString()
    {
        int amount = 1;
        input_event ev[amount];
        ev[0].code = BTN_9;
        ev[0].value = 1;
        char* temp = reinterpret_cast<char*>(ev);
        std::string msg(temp, sizeof(ev) * amount);
        return msg;
    }

};

class Child2 : public Parent
{
public:
    Child2(){
    }
    virtual std::string GetString()
    {
        std::string temp(Parent::GetString());
        return temp;
    }

};

TEST(CastToString, test)
{
    Parent parent = Parent();
    Child child1 = Child();
    Child2 child2 = Child2();
    std::string pString(parent.GetString());
    std::string c1String(child1.GetString());
    std::string c2String(child2.GetString());
    EXPECT_EQ(pString, c1String);
    EXPECT_EQ(pString, c2String);
}

I just copied in the whole sample.
The problem lies at the call of Child2s GetString function.
It always returns different values hence i assume, there is some allocation problem, but i cant figure it out.

  • 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-11T05:58:40+00:00Added an answer on June 11, 2026 at 5:58 am

    I think the error is here

      std::string msg(temp, sizeof(ev) * amount);
    

    should be

      std::string msg(temp, sizeof(ev[0]) * amount);
    

    (both places).

    Because the array size was wrong you were getting extra garbage bytes in your string, so they didn’t compare equal.

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

Sidebar

Related Questions

This is my code: #include <iostream> #include <fstream> using namespace std; int main() {
#include <iostream> #include <tuple> int main(){ auto bt=std::make_tuple(std::tuple<>(),std::tuple<std::tuple<>>()); //Line 1 auto bt2=std::make_tuple(std::tuple<>(),std::tuple<>()); //Line 2
here is the source code of the program. #include <stdio.h> #include <stdlib.h> #include <string.h>
I am using this code to read mouse events from the dev/input/event* in linux
Before Linux kernel 2.6, super_operations (include/linux/fs.h) have both read_inode and write_inode functions. But newer
In Linux, to create a socket we include the sys/socket.h header file and use
On Linux, with 16 GB of RAM, why would the following segfault: #include <stdlib.h> #define
I writing toolchain.cmake file for Linaro toolchain. include(CMakeForceCompiler) set(CMAKE_CROSSCOMPILING TRUE) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_VERSION 1)
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
#include<stdio.h> int main(int argc, char **argv) { int a,b,c; printf(enter two numbers:-); if( scanf(%d

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.