A struct inside a struct inside a templated class2019 Community Moderator ElectionWhat's the difference between struct and class in .NET?When should you use a class vs a struct in C++?Use 'class' or 'typename' for template parameters?Why can templates only be implemented in the header file?When to use struct?Where and why do I have to put the “template” and “typename” keywords?Difference between 'struct' and 'typedef struct' in C++?typedef struct vs struct definitionsContainers crash inside structs?Enable method based on boolean template parameter

If I cast the Enlarge/Reduce spell on an arrow, what weapon could it count as?

"Marked down as someone wanting to sell shares." What does that mean?

PTIJ: Which Dr. Seuss books should one obtain?

Pre-Employment Background Check With Consent For Future Checks

Error in master's thesis, I do not know what to do

How can an organ that provides biological immortality be unable to regenerate?

Why is this tree refusing to shed its dead leaves?

Can other pieces capture a threatening piece and prevent a checkmate?

Justification failure in beamer enumerate list

Why doesn't the chatan sign the ketubah?

Help with identifying unique aircraft over NE Pennsylvania

Homology of the fiber

Single word to change groups

Would this string work as string?

What are the rules for concealing thieves' tools (or items in general)?

Does the Shadow Magic sorcerer's Eyes of the Dark feature work on all Darkness spells or just his/her own?

Knife as defense against stray dogs

Norwegian Refugee travel document

Why do I have a large white artefact on the rendered image?

Does convergence of polynomials imply that of its coefficients?

Why I don't get the wanted width of tcbox?

Logic with "co-relations" - sources?

Do people actually use the word "kaputt" in conversation?

Writing in a Christian voice



A struct inside a struct inside a templated class



2019 Community Moderator ElectionWhat's the difference between struct and class in .NET?When should you use a class vs a struct in C++?Use 'class' or 'typename' for template parameters?Why can templates only be implemented in the header file?When to use struct?Where and why do I have to put the “template” and “typename” keywords?Difference between 'struct' and 'typedef struct' in C++?typedef struct vs struct definitionsContainers crash inside structs?Enable method based on boolean template parameter










-1















I have two structs inside a templated class: struct A and struct B.
struct A contains a vector of B values, and struct B contains a pointer to an A value.



I have a recursive function (called help) that receives a pointer to A as input. I want the function to loop through its vector of B values and recursively call the help function, with each A value stored in the B values, as input.



THE PROBLEM: this gives me a compiler error:



Cannot initialize a parameter of type 'Object<int>::A *' with an lvalue of type 'A *'


Relevant code in my header file:



struct A;

template<typename ValueType>
class Object

public:
struct B
// other things
A* ptr;
;

struct A
// other things
std::vector<B> arr;
;

void callHelp();
void help(A* a);
;

template<typename ValueType>
void Object<ValueType>::callHelp()
help(new A);


template<typename ValueType>
void Object<ValueType>::help(A* a)
if (a == nullptr) return;
for (typename std::vector<B>::iterator it = a->arr.begin(); it != a->arr.end(); it++)
help((*it).ptr);




In main:



int main() 
Object<int> o;
o.callHelp();










share|improve this question
























  • Move the forward declaration struct A; inside of the Object class declaration before using A*.

    – πάντα ῥεῖ
    Mar 6 at 23:29
















-1















I have two structs inside a templated class: struct A and struct B.
struct A contains a vector of B values, and struct B contains a pointer to an A value.



I have a recursive function (called help) that receives a pointer to A as input. I want the function to loop through its vector of B values and recursively call the help function, with each A value stored in the B values, as input.



THE PROBLEM: this gives me a compiler error:



Cannot initialize a parameter of type 'Object<int>::A *' with an lvalue of type 'A *'


Relevant code in my header file:



struct A;

template<typename ValueType>
class Object

public:
struct B
// other things
A* ptr;
;

struct A
// other things
std::vector<B> arr;
;

void callHelp();
void help(A* a);
;

template<typename ValueType>
void Object<ValueType>::callHelp()
help(new A);


template<typename ValueType>
void Object<ValueType>::help(A* a)
if (a == nullptr) return;
for (typename std::vector<B>::iterator it = a->arr.begin(); it != a->arr.end(); it++)
help((*it).ptr);




In main:



int main() 
Object<int> o;
o.callHelp();










share|improve this question
























  • Move the forward declaration struct A; inside of the Object class declaration before using A*.

    – πάντα ῥεῖ
    Mar 6 at 23:29














-1












-1








-1








I have two structs inside a templated class: struct A and struct B.
struct A contains a vector of B values, and struct B contains a pointer to an A value.



I have a recursive function (called help) that receives a pointer to A as input. I want the function to loop through its vector of B values and recursively call the help function, with each A value stored in the B values, as input.



THE PROBLEM: this gives me a compiler error:



Cannot initialize a parameter of type 'Object<int>::A *' with an lvalue of type 'A *'


Relevant code in my header file:



struct A;

template<typename ValueType>
class Object

public:
struct B
// other things
A* ptr;
;

struct A
// other things
std::vector<B> arr;
;

void callHelp();
void help(A* a);
;

template<typename ValueType>
void Object<ValueType>::callHelp()
help(new A);


template<typename ValueType>
void Object<ValueType>::help(A* a)
if (a == nullptr) return;
for (typename std::vector<B>::iterator it = a->arr.begin(); it != a->arr.end(); it++)
help((*it).ptr);




In main:



int main() 
Object<int> o;
o.callHelp();










share|improve this question
















I have two structs inside a templated class: struct A and struct B.
struct A contains a vector of B values, and struct B contains a pointer to an A value.



I have a recursive function (called help) that receives a pointer to A as input. I want the function to loop through its vector of B values and recursively call the help function, with each A value stored in the B values, as input.



THE PROBLEM: this gives me a compiler error:



Cannot initialize a parameter of type 'Object<int>::A *' with an lvalue of type 'A *'


Relevant code in my header file:



struct A;

template<typename ValueType>
class Object

public:
struct B
// other things
A* ptr;
;

struct A
// other things
std::vector<B> arr;
;

void callHelp();
void help(A* a);
;

template<typename ValueType>
void Object<ValueType>::callHelp()
help(new A);


template<typename ValueType>
void Object<ValueType>::help(A* a)
if (a == nullptr) return;
for (typename std::vector<B>::iterator it = a->arr.begin(); it != a->arr.end(); it++)
help((*it).ptr);




In main:



int main() 
Object<int> o;
o.callHelp();







c++ templates struct






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 6 at 23:47







Cindy Zhang

















asked Mar 6 at 23:25









Cindy ZhangCindy Zhang

11




11












  • Move the forward declaration struct A; inside of the Object class declaration before using A*.

    – πάντα ῥεῖ
    Mar 6 at 23:29


















  • Move the forward declaration struct A; inside of the Object class declaration before using A*.

    – πάντα ῥεῖ
    Mar 6 at 23:29

















Move the forward declaration struct A; inside of the Object class declaration before using A*.

– πάντα ῥεῖ
Mar 6 at 23:29






Move the forward declaration struct A; inside of the Object class declaration before using A*.

– πάντα ῥεῖ
Mar 6 at 23:29













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%2f55033788%2fa-struct-inside-a-struct-inside-a-templated-class%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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55033788%2fa-struct-inside-a-struct-inside-a-templated-class%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

AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

Алба-Юлія

Захаров Федір Захарович