Two-stage templated alias not resolvable in constructor?












0














I am trying to work with a two-stage templated alias, but I cannot get the alias to be accepted as a constructor parameter. Is there a way to do this?



An example of what I am trying to do is seen in the following code:



#include <memory>

template <typename Bar>
class Foo
{
public:
using FooPtr = std::shared_ptr<Foo<Bar> >;

static FooPtr getFooPtr(Bar someBar) { return std::make_shared<Foo<Bar> >(someBar); }
Foo(Bar bar) : _bar(bar) {}

Bar getBar() { return _bar; }

private:
Bar _bar;
};

template <typename Bar>
class Foobar
{
public:
using FB = Foo<Bar>;
Foobar(FB::FooPtr fooPtr)
: _fooPtr(fooPtr)
{
}

FB::FooPtr getFooPtr() { return _fooPtr; }

private:
FB::FooPtr _fooPtr;
};

int main()
{
Foobar myFoobar<int>(f::getFooPtr(4));
return myFoobar.getFooPtr()->getBar();
}


When I compile this with g++, I get the following:



dev@ubuntu:~/test/fsm$ g++ -std=c++1z test.cpp
test.cpp:23:23: error: expected ‘)’ before ‘fooPtr’
Foobar(FB::FooPtr fooPtr)
^
test.cpp:28:5: error: need ‘typename’ before ‘Foobar<Bar>::FB::FooPtr’ because ‘Foobar<Bar>::FB’ is a dependent scope
FB::FooPtr getFooPtr() { return _fooPtr; }
^
test.cpp:31:5: error: need ‘typename’ before ‘Foobar<Bar>::FB::FooPtr’ because ‘Foobar<Bar>::FB’ is a dependent scope
FB::FooPtr _fooPtr;
^
test.cpp: In function ‘int main()’:
test.cpp:36:11: error: missing template arguments before ‘myFoobar’
Foobar myFoobar<int>(f::getFooPtr(4));
^
test.cpp:37:11: error: ‘myFoobar’ was not declared in this scope
return myFoobar.getFooPtr()->getBar();


Is the compiler not recognizing the alias FB in the Foobar constuctor? Or is it a problem with resolving Foo::FooPtr to a type?



Thanks!










share|improve this question






















  • The error message is clear: "error: need ‘typename’ before ‘Foobar<Bar>::FB::FooPtr’". You have to add typename before FB::FooPtr
    – max66
    Nov 13 '18 at 3:18










  • You are completely right. I missed it because I was looking at the first error message (from line 23) which does not specify that 'typename' is missing. Adding 'typename' does fix all the cases. Thanks!
    – Moe42
    Nov 14 '18 at 2:05
















0














I am trying to work with a two-stage templated alias, but I cannot get the alias to be accepted as a constructor parameter. Is there a way to do this?



An example of what I am trying to do is seen in the following code:



#include <memory>

template <typename Bar>
class Foo
{
public:
using FooPtr = std::shared_ptr<Foo<Bar> >;

static FooPtr getFooPtr(Bar someBar) { return std::make_shared<Foo<Bar> >(someBar); }
Foo(Bar bar) : _bar(bar) {}

Bar getBar() { return _bar; }

private:
Bar _bar;
};

template <typename Bar>
class Foobar
{
public:
using FB = Foo<Bar>;
Foobar(FB::FooPtr fooPtr)
: _fooPtr(fooPtr)
{
}

FB::FooPtr getFooPtr() { return _fooPtr; }

private:
FB::FooPtr _fooPtr;
};

int main()
{
Foobar myFoobar<int>(f::getFooPtr(4));
return myFoobar.getFooPtr()->getBar();
}


When I compile this with g++, I get the following:



dev@ubuntu:~/test/fsm$ g++ -std=c++1z test.cpp
test.cpp:23:23: error: expected ‘)’ before ‘fooPtr’
Foobar(FB::FooPtr fooPtr)
^
test.cpp:28:5: error: need ‘typename’ before ‘Foobar<Bar>::FB::FooPtr’ because ‘Foobar<Bar>::FB’ is a dependent scope
FB::FooPtr getFooPtr() { return _fooPtr; }
^
test.cpp:31:5: error: need ‘typename’ before ‘Foobar<Bar>::FB::FooPtr’ because ‘Foobar<Bar>::FB’ is a dependent scope
FB::FooPtr _fooPtr;
^
test.cpp: In function ‘int main()’:
test.cpp:36:11: error: missing template arguments before ‘myFoobar’
Foobar myFoobar<int>(f::getFooPtr(4));
^
test.cpp:37:11: error: ‘myFoobar’ was not declared in this scope
return myFoobar.getFooPtr()->getBar();


Is the compiler not recognizing the alias FB in the Foobar constuctor? Or is it a problem with resolving Foo::FooPtr to a type?



Thanks!










share|improve this question






















  • The error message is clear: "error: need ‘typename’ before ‘Foobar<Bar>::FB::FooPtr’". You have to add typename before FB::FooPtr
    – max66
    Nov 13 '18 at 3:18










  • You are completely right. I missed it because I was looking at the first error message (from line 23) which does not specify that 'typename' is missing. Adding 'typename' does fix all the cases. Thanks!
    – Moe42
    Nov 14 '18 at 2:05














0












0








0







I am trying to work with a two-stage templated alias, but I cannot get the alias to be accepted as a constructor parameter. Is there a way to do this?



An example of what I am trying to do is seen in the following code:



#include <memory>

template <typename Bar>
class Foo
{
public:
using FooPtr = std::shared_ptr<Foo<Bar> >;

static FooPtr getFooPtr(Bar someBar) { return std::make_shared<Foo<Bar> >(someBar); }
Foo(Bar bar) : _bar(bar) {}

Bar getBar() { return _bar; }

private:
Bar _bar;
};

template <typename Bar>
class Foobar
{
public:
using FB = Foo<Bar>;
Foobar(FB::FooPtr fooPtr)
: _fooPtr(fooPtr)
{
}

FB::FooPtr getFooPtr() { return _fooPtr; }

private:
FB::FooPtr _fooPtr;
};

int main()
{
Foobar myFoobar<int>(f::getFooPtr(4));
return myFoobar.getFooPtr()->getBar();
}


When I compile this with g++, I get the following:



dev@ubuntu:~/test/fsm$ g++ -std=c++1z test.cpp
test.cpp:23:23: error: expected ‘)’ before ‘fooPtr’
Foobar(FB::FooPtr fooPtr)
^
test.cpp:28:5: error: need ‘typename’ before ‘Foobar<Bar>::FB::FooPtr’ because ‘Foobar<Bar>::FB’ is a dependent scope
FB::FooPtr getFooPtr() { return _fooPtr; }
^
test.cpp:31:5: error: need ‘typename’ before ‘Foobar<Bar>::FB::FooPtr’ because ‘Foobar<Bar>::FB’ is a dependent scope
FB::FooPtr _fooPtr;
^
test.cpp: In function ‘int main()’:
test.cpp:36:11: error: missing template arguments before ‘myFoobar’
Foobar myFoobar<int>(f::getFooPtr(4));
^
test.cpp:37:11: error: ‘myFoobar’ was not declared in this scope
return myFoobar.getFooPtr()->getBar();


Is the compiler not recognizing the alias FB in the Foobar constuctor? Or is it a problem with resolving Foo::FooPtr to a type?



Thanks!










share|improve this question













I am trying to work with a two-stage templated alias, but I cannot get the alias to be accepted as a constructor parameter. Is there a way to do this?



An example of what I am trying to do is seen in the following code:



#include <memory>

template <typename Bar>
class Foo
{
public:
using FooPtr = std::shared_ptr<Foo<Bar> >;

static FooPtr getFooPtr(Bar someBar) { return std::make_shared<Foo<Bar> >(someBar); }
Foo(Bar bar) : _bar(bar) {}

Bar getBar() { return _bar; }

private:
Bar _bar;
};

template <typename Bar>
class Foobar
{
public:
using FB = Foo<Bar>;
Foobar(FB::FooPtr fooPtr)
: _fooPtr(fooPtr)
{
}

FB::FooPtr getFooPtr() { return _fooPtr; }

private:
FB::FooPtr _fooPtr;
};

int main()
{
Foobar myFoobar<int>(f::getFooPtr(4));
return myFoobar.getFooPtr()->getBar();
}


When I compile this with g++, I get the following:



dev@ubuntu:~/test/fsm$ g++ -std=c++1z test.cpp
test.cpp:23:23: error: expected ‘)’ before ‘fooPtr’
Foobar(FB::FooPtr fooPtr)
^
test.cpp:28:5: error: need ‘typename’ before ‘Foobar<Bar>::FB::FooPtr’ because ‘Foobar<Bar>::FB’ is a dependent scope
FB::FooPtr getFooPtr() { return _fooPtr; }
^
test.cpp:31:5: error: need ‘typename’ before ‘Foobar<Bar>::FB::FooPtr’ because ‘Foobar<Bar>::FB’ is a dependent scope
FB::FooPtr _fooPtr;
^
test.cpp: In function ‘int main()’:
test.cpp:36:11: error: missing template arguments before ‘myFoobar’
Foobar myFoobar<int>(f::getFooPtr(4));
^
test.cpp:37:11: error: ‘myFoobar’ was not declared in this scope
return myFoobar.getFooPtr()->getBar();


Is the compiler not recognizing the alias FB in the Foobar constuctor? Or is it a problem with resolving Foo::FooPtr to a type?



Thanks!







templates alias






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 3:13









Moe42

333




333












  • The error message is clear: "error: need ‘typename’ before ‘Foobar<Bar>::FB::FooPtr’". You have to add typename before FB::FooPtr
    – max66
    Nov 13 '18 at 3:18










  • You are completely right. I missed it because I was looking at the first error message (from line 23) which does not specify that 'typename' is missing. Adding 'typename' does fix all the cases. Thanks!
    – Moe42
    Nov 14 '18 at 2:05


















  • The error message is clear: "error: need ‘typename’ before ‘Foobar<Bar>::FB::FooPtr’". You have to add typename before FB::FooPtr
    – max66
    Nov 13 '18 at 3:18










  • You are completely right. I missed it because I was looking at the first error message (from line 23) which does not specify that 'typename' is missing. Adding 'typename' does fix all the cases. Thanks!
    – Moe42
    Nov 14 '18 at 2:05
















The error message is clear: "error: need ‘typename’ before ‘Foobar<Bar>::FB::FooPtr’". You have to add typename before FB::FooPtr
– max66
Nov 13 '18 at 3:18




The error message is clear: "error: need ‘typename’ before ‘Foobar<Bar>::FB::FooPtr’". You have to add typename before FB::FooPtr
– max66
Nov 13 '18 at 3:18












You are completely right. I missed it because I was looking at the first error message (from line 23) which does not specify that 'typename' is missing. Adding 'typename' does fix all the cases. Thanks!
– Moe42
Nov 14 '18 at 2:05




You are completely right. I missed it because I was looking at the first error message (from line 23) which does not specify that 'typename' is missing. Adding 'typename' does fix all the cases. Thanks!
– Moe42
Nov 14 '18 at 2:05












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273255%2ftwo-stage-templated-alias-not-resolvable-in-constructor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273255%2ftwo-stage-templated-alias-not-resolvable-in-constructor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly