calling static function from constructor of same class [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
can we call static function from constructor of same class.
class a{
static void fun();
a() {fun();}
};
it is giving an error while linking code. I am using visual studio C++, 2010.

Yes you can - as long as you provide a function definition for the static function as well.

I don't really understand the question.
If you provide a function definition as said by Billz and Ogni42, it will work.
The following code does compile, and work:
#include <iostream>
class a {
public:
a() { fun(); }
private:
static void fun();
};
void a::fun() {
std::cout << "BOAP" << std::endl;
}
int main() {
a foo;
return 0;
}

Related

Unable to access helper functions not in the namespace: undeclared identifier [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 12 months ago.
Improve this question
I currently have a namespace set up like this:
SomeClass.h
namespace somenamespace {
class SomeClass {
public:
foo();
}
}
SomeClass.cpp
namespace somenamespace {
SomeClass::foo() {
somehelperfunction();
}
}
void somehelperfunction() {
std::cout << "hejflsdjf\n";
}
Without changing my header file, I cannot find a way to implement this helper function in a way which allows my class implementation to access the helper function. I was under the impression that as long as the helper function was in the same file I would be able to access it within the class implementation. But I get a "undeclared identifier" error when trying to build.
Functions must be declared before called.

unsorted_set hashing error [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
I recently started to make a game with a friend, but we now encountered a problem with unsorted lists. I checked this site and other forums, but nothing seems to work.
Here's the code: http://pastebin.com/nx8sf6T2
And the compiler error: http://pastebin.com/fdQ7B0Dx
(And for compiling I use "clang++ -std=c++11 main3D.cpp", in case anyone is wondering)
hash<point> must be known at the time of instantiation of std::unordered_set<point>, and that requires point to be known before hash<point>:
struct point
{
// contents...
};
namespace std
{
template<>
struct hash<point>
{
// contents...
};
}
struct line
{
std::unordered_set<point> points;
// contents...
};
namespace std
{
template<>
struct hash<line>
{
// contents...
};
}
Demo

strange behaviour.. please suggest some solution [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have encountered one very strange problem. I am trying to explain full scenario here. Please suggest some solution.
/* "test.h" */
class A : public B
{
public:
A();
bool isUp;
};
/* test.cpp */
#include "test.h"
A::A()
{
isUp = false; //`isUp' was not declared in this scope
}
What is it means if I am declaring it in .h inside class. If I am wrong then what approach I need to follow.
EDIT :
class B
{
public:
sem_t m_job_count; //added by RajaGopal
B();
void Init();
void Init(char * s,int );
void RegisterWorker(worker *aWorker);
unsigned long getIndex();
void setIndex(unsigned long index);
char Msg[200];
static void* ThreadProc(void *p);
~B();
};
Where is the definition of class B. Since you are inheriting class B, compiler needs to know the definition of class B. Include its header file or its definition too.
Class definition of B should be visible to A.
Otherwise, I have compiled this code here and did not faced any problem.

Problem using recursive method in c++ [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 5 years ago.
Improve this question
I have a class, defined in a .h like this
#ifndef JLLABOUR_H
#define JLLABOUR_H
class JLLabour{
public:
JLLabour(int, int);
double* recursivefft(double*,int);
void FFT(int*);
~JLLabour();
private:
int width;
int height;
};
#endif // JLLABOUR_H
and in my .cpp I have the definition of my recursive function, the problem is that when I call it again , during compilation it doesnt allow me to continue because the method has not been defined yet. I dont know how to solve this, please help.
#include <JLLabour.h>
double* JLLabour::recursivefft(double* x,int asize){
//operations and declartions...
//...
even = recursiveFFT(sum,m); //<-- the problem is here, in the recursion.
odd = recursiveFFT(diff,m);
// more operations....
return result;
}
}
FYI I am compiling under Linux, using Qt because Im developing a graphic app...
C++ is case sensitive. Your method is called recursivefft not recursiveFFT.

C++ - Unresolved external symbols [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 14 years ago.
Improve this question
Simply put:
foo.h:
#include "bar.h"
class foo {
private:
bar it;
void DoIt();
}
bar.h:
class bar {
public:
void Test();
}
foo.cpp:
void foo::DoIt() {
it.Test();
}
This will result in a:
error LNK2001: unresolved external symbol
Why?
You have not written the code for bar::Test() method.
I'm dumb! I did define Test() in the class definition but did not actually have an existing Test() function :(
Sorry.