Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 3 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
Can I write code like this (tried it and doesn't compile in VS2015):
template<class BaseClassT>
class DerivedClass : public BaseClassT
{
...
};
and then use it like:
class BaseClass
{
};
DeriveClass<BaseClass> c;
if not possible, is there a way to implement the same idea?
Yes, you may use a template argument as base, and it compiles in MSVS if you fix the typo.
(Note that this is not the CRTP, despite what you may have heard.)
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 3 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I am making a stack class, and trying to make an object of it and using it in another class. However, it mentions that there is an error.
here's my code of intializing the stack object in the class:
class functions{
public:
int m[5];
int c=0;
stack_x mem(5);
You can't initialise members using parentheses in the class definition.
Use curly braces — stack_x mem{5};.
If the previous class (stack_x) looks like an custom class its correctly closed
class stack_x
{
// Class definition
}; // MUST BE
class functions
{
// Class definition
};
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I encountered this code:
NAMESPACE_NCO_BEGIN
class NCO_VIEWS_DECLSPEC MyView:
public CWnd
{
};
NAMESPACE_NCO_END
What does the NCO_VIEWS_DECLSPEC mean?
MyView is class name.
If possible try to explain NAMESPACE_NCO_BEGIN and NAMESPACE_NCO_END.
All three are macros. Somewhere in the code, possibly in some included header file, there must be #defines for them. NCO_VIEWS_DECLSPEC most certainly translates to some compiler-specific class attribute, e.g. __declspec( dllexport) for Microsoft Visual C++. Look here for a detailed example: Using dllimport and dllexport in C++ Classes
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I declare in a header traductionCSV.h the function
static QVector<struct variableDurSupervision>
listVariableDurSupervison(std::string fichierCSV);
I write it in my cpp, then I want to use it in another file supervision.cpp, so I call it like this :
remplirDurCellule(
traductionCSV::listVariableDurSupervison(
"../../FichierCSV/ListeVariableSupervision.csv"
)
);
But it won't work, I got this error :
undefined reference to traductionCSV::listVariableDurSupervison(std::string)
I properly include all the file, so I don't understand.
Thank you.
You are probably missing the class name when you are defining it in cpp. It should be like :
QVector<struct variableDurSupervision> traductionCSV::listVariableDurSupervison(std::string fichierCSV)
{
...
}
This rule applies both to static and non-static functions of a class.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I was practising using C++ templates (sounds way better than "playing around") by coding something that would basically be my own implementation of std::array when I stumbled across an odd compilation failure. I reduced the problem into the following class, which fails to compile on gcc version 4.9.0:
template <typename TestType>
class TestClass
{
TestType[10] data;
};
What am I doing wrong here?
The array part of the type should go after the identifier:
TestType data[10];
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I got a error message while compiling, saying that
node.h: In member function ‘void binary_tree::print(node*&, std::ofstream&)’:
node.h:17:10: error: ‘node* node::left_child’ is private
But in node.h, the member is public
class node {
public:
char *word;
int frequency;
node *left_child;
node *right_child; };
using MinGW for build and run. Pls help me in solving this issue.
You need to submit complete code for comments.
Error cannot occur if left_child is public. You can clean and rebuild your code.
binary_tree how is this class using class node?
it just worked well!!! but some kinda build error takes here. And this is the altered codes here - https://drive.google.com/file/d/0B5PwxyqEos-wb05vRzhvN21aYTQ/edit?usp=sharing