Error while compiling the code [closed] - c++

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

Related

Base class and templates [closed]

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.)

error: expected ';', ',' or ') before numeric constant [closed]

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
};

Unable to compile - scope issues [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 3 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 have copied program on Simulated Annealing from a book (first result link here) and am facing the below issues on compilation, for below line in main().
srand48(tp.tv_usec);
Error on compiling with Dev-C++:
[Error] 'srand48' was not declared in this scope
The full code is at: https://onlinegdb.com/HyruMTmdN.
& the relevant (trimmed version) is stated below:
#include <sys/time.h>
extern double drand48();
extern long lrand48(/*long*/);
extern int rand();
extern void srand(long seedval);
//main program
main()
{
//set random number generator
struct timeval tp;
struct timezone tzp;
gettimeofday(&tp,&tzp);
srand48(tp.tv_usec);
return 1;
}
pop() is a function and is being indexed as if it were a variable. With a quick look there is an array op which might be what’s needed here. So maybe it should be op[x] and not pop[x] in these places?
And when looking at the original that’s how it is. So a copying error by user, should be closed.

Can't call a static function [closed]

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.

C-style static array as a member of a template class - won't compile [closed]

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];