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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:03:31+00:00 2026-06-18T09:03:31+00:00

I have a C++/Win32/MFC project in Visual Studio 2008, and I’m getting a strange

  • 0

I have a C++/Win32/MFC project in Visual Studio 2008, and I’m getting a strange error message when I compile it.

I’ve created a small project to demonstrate the problem, and the main code is

#ifndef _MyObject_h
#define _MyObject_h

class MyObject
{
public:
        MyObject()
        {
        }
};

#endif // _MyObject_h
// --- END MyObject.h



// --- BEGIN ObjectData.h
#ifndef _ObjectData_h
#define _ObjectData_h

template <typename DataPolicy>
class ObjectData
{
public:
        DataPolicy *data;

        ObjectData() :
                data(NULL)
        {
        }

        ObjectData(const ObjectData<DataPolicy> &copy) :
                data(copy.data)
        {
        }

        ObjectData<DataPolicy> & operator=(const ObjectData<DataPolicy> &copy)
        {
                this->data = copy.data;
                return *this;
        }
};

#endif // _ObjectData_h
// --- END ObjectData.h



// --- BEGIN Tool.h
#ifndef _Tool_h
#define _Tool_h

#include "ObjectData.h"

template <typename ObjectPolicy>
class Tool
{
private:
        ObjectData<typename ObjectPolicy> _object;

public:
        Tool(ObjectData<typename ObjectPolicy> obj);
};

#endif // _Tool_h
// --- END Tool.h



// --- BEGIN Tool.cpp
#include "stdafx.h"
#include "Tool.h"

template <typename ObjectPolicy>
Tool<ObjectPolicy>::Tool(ObjectData<typename ObjectPolicy> obj) :
        _object(obj)
{
}
// --- END Tool.cpp



// --- BEGIN Engine.h
#ifndef _Engine_h
#define _Engine_h

#include "Tool.h"
#include "MyObject.h"

class Engine
{
private:
        MyObject *_obj;

public:
        Engine();
        ~Engine();
        void DoSomething();
};

#endif // _Engine_h
// --- END Engine.h



// --- BEGIN Engine.cpp
#include "stdafx.h"
#include "Engine.h"

Engine::Engine()
{
        this->_obj = new MyObject();
}

Engine::~Engine()
{
        delete this->_obj;
}

void Engine::DoSomething()
{
        ObjectData<MyObject> objData;
        objData.data = this->_obj;
        // NEXT LINE IS WHERE THE ERROR OCCURS
        Tool< ObjectData<MyObject> > *tool = new Tool< ObjectData<MyObject> >(objData);
}
// --- END Engine.cpp

Errors:

Engine.cpp
c:\projects\myproject\myproject\engine.cpp(18) : error C2664:
‘Tool::Tool(ObjectData)’ : cannot convert parameter 1 from ‘ObjectData’ to ‘ObjectData’
with
[
ObjectPolicy=ObjectData,
DataPolicy=ObjectData
]
and
[
DataPolicy=MyObject
]
and
[
DataPolicy=ObjectData
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>Build log was saved at “file://c:\Projects\MyProject\MyProject\Debug\BuildLog.htm”
MyProject – 1 error(s), 0 warning(s)

Thanks for any help.

  • 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-18T09:03:32+00:00Added an answer on June 18, 2026 at 9:03 am

    There are a few problems with your code. First of all, you are using the typename keyword in a wrong way. typename can be used only when qualified type names are used (and is required when the type names are dependent), which is not your case:

    template <typename ObjectPolicy>
    class Tool
    {
    private:
        ObjectData<typename ObjectPolicy> _object; // "typename" is not needed!
    public:
        Tool(ObjectData<typename ObjectPolicy> obj); // "typename" is not needed!
    };
    

    The problem you complain about, however, is in your instantiation of the Tool class template:

    Tool< ObjectData<MyObject> > *tool = new Tool< ObjectData<MyObject> >(objData);
    

    Your Tool<> template contains a member variable of type ObjectData<ObjectPolicy>, where ObjectPolicy is the class template parameter. However, in the line above you instantiate Tool with ObjectData<MyObject> as a parameter. This means your member variable will have type ObjectData<ObjectData<MyObject>>, and this will also be the type of the constructor’s parameter.

    Because of this, you are trying to invoke a constructor which accepts an ObjectData<ObjectData<MyObject>> with an argument of a mismatching type ObjectData<MyObject>. Hence, the error you get.

    You should change your instantiation into:

    Tool< MyObject > *tool = new Tool< MyObject >(objData);
    

    Another problem is that you have the definition of Tool‘s member functions in a separate .cpp files. You should not do that: the linker won’t be able to see it when processing a separate translation unit.

    To solve this problem, put the definitions of your class template’s member functions into the same header where the class template is defined (Tool.h in your case).

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

Sidebar

Related Questions

I have a Visual Studio 2010 project done on MFC. I receive these errors:
I have a C++ project in the MS Visual Studio 2008 IDE (note, NO
I have a number of native C++ libraries (Win32, without MFC) compiling under Visual
I have a Visual Studio 2010 project with C++ code that I want to
I would like to make a Win32 DLL (unmanaged code) using Visual Studio 2008.
I am having several problems with tessdll in Visual Studio 2008. FYI, I created
I'm working on MFC win32 project. I have dialog with 2 CMFCEditBrowseCtrl controls. After
I'm working on a win32/MFC project. I have a custom CListCtrl control that I
I have a win32 GUI (MFC) application which I need to port to a
I have Visual Studio 2010 with SP1 installed. I want to create a simple

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.