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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:52:45+00:00 2026-05-14T05:52:45+00:00

//file list.h #include stdafx.h namespace st { struct My_List; typedef My_List list; list* create(const

  • 0
//file list.h
#include "stdafx.h"

namespace st
{
    struct My_List;
    typedef My_List list;
    list* create(const char* name);
}

//file list.cpp
#include "stdafx.h"
#include "list.h"
namespace st
{
    struct My_List
    {
        const char* name_;
        My_List* left_;
        My_List* right_;

        My_List(const char* name):name_(name),
            left_(nullptr),
            right_(nullptr)
        {}
        My_List(const My_List&);

        ~My_List()
        {

        }
        void insert(My_List*);

        void set_name(char* name)
        {

            name_ = name;
        }

        const char* get_name()const
        {
            return name_;
        }
    };
    typedef My_List list;

    /*helper class for optor+ */
    struct MyChar
    {
        const char* my_data_;
        MyChar(const char* c_string):my_data_(c_string){}
        operator const char*()
        {
            return my_data_;
        }
        operator char*()
        {
            return const_cast<char*>(my_data_);
        }

    };

    char* operator+(MyChar left_, MyChar right_)
    {
        if (!left_.my_data_ || !right_.my_data_)
        {
            return 0;
        }
        size_t size = 1;//size is set to one for final '\0' char in an array
        char* p = "";//if both c_strings are empty this is returned
        bool has_left_ = false;
        bool has_right_ = false;
        if (strlen(left_))
        {
            size += strlen(left_);
            has_left_ = true;
        }
        if (strlen(right_))
        {
            size += strlen(right_);
            has_right_ = true;
        }
        bool both = has_left_ && has_right_ ? true : false;
        if (both)
        {
            p = new char[size]();
            const void* p_v = p;//just to keep address of beginning of p
            const char* tmp = left_;
            /*copying first c_string*/
            while (*p++ = *tmp++);

            tmp = right_;
            /*one too far after last loop*/
            --p;
            while (*p++ = *tmp++);

            *p = '\0';
            /*go back to the beginning of an array*/
            p = static_cast<char*>(const_cast<void*>(p_v));
            return p;
        }
        else if (has_left_)
        {
            return left_;
        }
        else if (has_right_)
        {
            return right_;
        }
        return p;//returns "" if both c_strings were empty
    }


    My_List::My_List(const My_List& pat):left_(nullptr),right_(nullptr)
    {
        name_ = pat.name_ + MyChar("_cpy");
        My_List* pattern = const_cast<My_List*>(&pat);
        My_List* target = this;
        while (pattern->right_)
        {

            target->right_ = static_cast<My_List*>(malloc(sizeof(My_List)));
            *target->right_ = *pattern->right_;
            target->right_->set_name(pattern->right_->get_name() + MyChar("_cpy"));
            target->right_->left_ = static_cast<My_List*>(malloc(sizeof(My_List)));
            *target->right_->left_ = *pattern->right_->left_;
            target->right_->left_->set_name(pattern->right_->left_->get_name() + MyChar("_cpy"));
            pattern = pattern->right_;
            target = target->right_;
        }
    }

    void My_List::insert(My_List* obj)
    {
        /*to catch first branch*/
        My_List* tmp = this;
        if (tmp->right_)
        {
            /*go to the end of right side*/
            while (tmp->right_)
            {
                tmp = tmp->right_;
            }

            tmp->right_ = obj;
            obj->left_ = tmp;
        }
        else
        {
            tmp->right_ = obj;
            obj->left_= this;
        }
    }
    My_List* create(const char* name)
    {
        return new My_List(name);
    }
}

//file main.cpp
#include "stdafx.h"
#include "list.h"
using namespace st;

int _tmain(int argc, _TCHAR* argv[])
{

    list* my = create("a");
    list* b = create("b");
    my->insert(b);//HERE I'M GETTING ERROR
    return 0;
}

err msg:
‘Error 1 error C2027: use of undefined type ‘st::My_List’ 13′

Why? Especially that if I comment this line it will get compiled and create() is using this type.

  • 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-14T05:52:45+00:00Added an answer on May 14, 2026 at 5:52 am

    You have done only a forward declaration in header file list.h. The actual definition is in list.cpp. While compiling main.cpp you are including list.h, so compiler doesn’t know what methods are there in the class My_List. You need to move the struct definition to header file list.h, you can still keep the method implementation in list.cpp

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

Sidebar

Ask A Question

Stats

  • Questions 373k
  • Answers 373k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Instead of "If", use "While" - in other words, keep… May 14, 2026 at 7:30 pm
  • Editorial Team
    Editorial Team added an answer could the code after the header-location call be effectively executed?… May 14, 2026 at 7:30 pm
  • Editorial Team
    Editorial Team added an answer It's because you can't overload operators for a pointer type;… May 14, 2026 at 7:30 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.