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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:56:04+00:00 2026-06-12T03:56:04+00:00

I have a strange compilation warning for the following code, with Visual C++ 2010:

  • 0

I have a strange compilation warning for the following code, with Visual C++ 2010:

#include <iostream>

class test
{
    public:
        template<class obj>
        class inner
        {
        private:
            // Line 11:
            template<int index, bool unused = true> struct AttributeName;

        private:
            template<bool b>
            struct AttributeName<0,b>
            {
                static inline const char* get()
                {
                    return "prop";
                }
            };

        public:
            typedef AttributeName<0> propname;
        };
        typedef inner<test> description;
};

int main()
{
    test t;
    std::cout << test::description::propname::get(); // Line 32
    return 0;
}

The warning:

file.cpp(11) : warning C4348: 'test::inner<obj>::AttributeName' : redefinition of default parameter : parameter 2 (with [ obj=test ])
file.cpp(11) : see declaration of 'test::inner<obj>::AttributeName' (with [ obj=test ])
file.cpp(32) : see reference to class template instantiation 'test::inner<obj>' being compiled (with [ obj=test ])

What I don’t understand is that AttributeName “redefinition” is at the same line than the definition… sounds like a bug

I noticed that making inner a non-template class removes the warning. However, this is not an option since the real code is more complicated than this testcase and need to be templated.

Also, this code won’t compile if warning are treated as errors…

It compiles without warnings on GCC.

Why msvc is outputing such warning and is there a workaround ?

edit

The following modification:

template<int index, bool unused = true> struct AttributeName {};

seems to erase the warning.

  • 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-12T03:56:05+00:00Added an answer on June 12, 2026 at 3:56 am

    This is mostly a guess, as this seems to solve(?) it:

    template<int index, bool unused = true> struct AttributeName;
    template<int index, bool unused> struct AttributeName
    {
    };
    

    My guess is that the forward declaration is seen as both a declaration and a “definition” since it can’t see anything else, hence it complains about the default being “redefined” even though it’s the same line. Could be unintentional, although 2012 behaves the same.

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

Sidebar

Related Questions

So strange! Please have a look the code first: public class A {} public
I have he following interface: template <class T> class AbstractTask { public: virtual void
I have this code in a single file : public class genIntro { public
I have a strange problem. On Windows, with Visual Studio 2010 and also with
I have strange behaviour in Python/PyMongo. dbh = self.__connection__['test'] first = dbh['test_1'] second =
While analyzing some library code supplied by another company we have come across strange
I've noticed a strange thing in the Visual Studio 2010 Prosessional (in the ASP.NET
The following F# code declares base and descendant classes. The base class has a
I've come across a strange thing. Visual Studio 2008 Project: Include/Libraries folder of the
This code compiles but looks very strange. I have a typical and simple parent/child

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.