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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:44:58+00:00 2026-06-04T14:44:58+00:00

My native language is C#, so when I started using C++, I wanted to

  • 0

My native language is C#, so when I started using C++, I wanted to create the get/set sugar syntax for library consumers available in C#.

So I wrote…

template<typename T>
class GetProperty
{
    private:
        T (*get)();
    public:
        GetProperty(T (*get)())
        {
            this->get = get;
        }
        operator T()
        {
            return get();
        }
        template<typename S, typename T>
        GetProperty<S> operator=(GetProperty<T> fool)
        {
            throw 0;
        }
 };

Then, to to use this, I wrote the code:

template<typename T>
class Vector
{
    private:
        struct LinkItem
        {
            public:
                T* Item;
                LinkItem* Next;
                                GetProperty<int> Length (&getLength);
                LinkItem(T* Item = NULL, int length = 1, LinkItem* Next = NULL)
                {
                    this->Item = Item;
                    this->length = length;
                    this->Next = Next;
                }
                LinkItem& operator =(LinkItem rhs)
                {
                    this->Item = rhs.Item;
                    this->length = rhs.length;
                    this->Next = rhs.Next;
                    return *this;
                }
            private:
                 int length;
                 int getLength()
                 {
                     return length;
                 }
        };
        LinkItem* current;
    .
    .
    .
};

However, the C/C++ addition on Netbeans (I believe this is the g++ compiler) claims I am instantiating GetProperty with no type.
According to a Google search, this happens if someone forgets a using statement, or to include a header, etc.
But int is a primitive, so this can’t be.
What’s going on?

  • 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-04T14:44:59+00:00Added an answer on June 4, 2026 at 2:44 pm

    In addition to the fact that VC++ doesn’t implement non-static data member initializers, you can’t treat the member function getLength as an int (*)(). Its type is int (LinkItem::*)().

    struct Foo {
        int foo(void) {return 1;}
    };
    
    int main() {
        int (*var)() = &Foo::foo; // Error
        int (Foo::*var)() = &Foo::foo; // Okay
    }
    

    You probably shouldn’t be trying to import a foreign idiom like this, but if you really want to you can try something like the following. (Though as Nicol Bolas points out, you also probably shouldn’t be implementing your own linked list, or naming it ‘vector’. If you’re learning C++ just learn the C++ way before going and trying to reinvent things.)

    #include <functional>
    
    template<typename T>
    class GetProperty
    {
    private:
        std::function<int()> get;
    public:
        GetProperty(std::function<int()> get)
            : get(get)
        {}
        operator T()
        {
            return get();
        }
    };
    
    template<typename T>
    class Vector
    {
    private:
        struct LinkItem
        {
        public:
            T* Item;
            LinkItem* Next;
            GetProperty<int> Length;
            LinkItem(T* Item = NULL, int length = 1, LinkItem* Next = NULL)
                : Length([this] { return this->getLength(); })
            {
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently started using Emacs for editing. When I edit english-language files (like program
In my application(GWT(EXT_GWT) + Spring) I need to set user(after login) his native language,
Because of my native language good for web designing fonts are not available. I
How do I get datetime.datetime.now() printed out in the native language? >>> session.deathDate.strftime("%a, %d
If your native language is not EN_US or you know any other spoken language
I have a legacy Java (not my native language) app that I'm trying to
i am developing a project that its domain is meaningful in my native language.
Excuse me for my poor English, that is not my native language. I'm a
with native SQL I get the database time with a statement like: SELECT CURRENT_TIMESTAMP
English is not my native language. I need a software to spellcheck and correct

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.