c++ - struct isn't recognized when using in a header file [closed] - c++

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 4 years ago.
Improve this question
I have a file named: FeedbackCircuitVariables.h with the following inside:
#pragma once
struct FeedbackCircuitVariables {
// Unknown values (the ones which will be calculated).
float m_Ic, m_Ib;
float m_Vce;
// Known values (the ones asked to user through keyboard).
float m_Rc, m_Rb, m_Re;
float m_Vbe, m_Vcc;
};
And a class in FeedbackCircuit.h:
#pragma once
#include "FeedbackCircuitVariables.h"
class FeedbackCircuit {
private:
FeedbackCircuitVariables *m_pVariables;
public:
FeedbackCircuit(const FeedbackCircuitVariables *variables);
};
And this is the definition of that class:
#include "FeeedbackCircuit.h"
FeedbackCircuit(const FeedbackCircuitVariables *variables) {
}
But inside the header of the class the compiler says that FeedbackCircuitVariables isn't a type name.
What am I doing wrong?

Your constructor syntax is wrong.
Change:
FeedbackCircuit(const FeedbackCircuitVariables *variables)
To:
FeedbackCircuit::FeedbackCircuit(const FeedbackCircuitVariables *variables)
// ^^^^^^^^^^^^^^^^^ This is the scope of the thing you're defining.
Your code should build then.

You have to set the scope of FeedbackCircuit(const FeedbackCircuitVariables *variables) in FeedbackCircuit.cpp:
FeedbackCircuit::FeedbackCircuit(const FeedbackCircuitVariables *variables) {
}
Add FeedbackCircuit:: to tell the editor and compiler where the function is located.

Related

C++ (Atom GCC compiler) "no declaration matches 'int ClassName::FuncName(Paramaters)'" using non-numerical types / ignoring set type for default [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 1 year ago.
Improve this question
I have been getting this Compiler/Linter Error every time I try to create a function member of a class with a return type other than int, double, and similar types. As far as I can tell, the compiler is setting the default int return type for these functions. But I can't figure out why. I have no excess header or cpp files in the directory, which I have also read can cause the problem.
The error is shows up under the addSample function.
error: no declaration matches 'int BinaryCounter::addSample(std::cxx11::string)' BinaryCounter::addSample(std::string sample)
Using these .cpp and .h files. Main is currently empty.
#include <vector>
#include <string>
class BinaryCounter
{
public:
BinaryCounter();
BinaryCounter(std::string sample);
~BinaryCounter();
std::vector<int> addSample(std::string sample);
std::vector<int> oneCountColumns;
int binaryLength;
};
#include "BinaryCounter.h"
BinaryCounter::BinaryCounter()
{
}
BinaryCounter::~BinaryCounter()
{
}
BinaryCounter::BinaryCounter(std::string sample)
{
binaryLength = sample.length();
}
BinaryCounter::addSample(std::string sample)
{
return oneCountColumns;
}
std::vector<int> addSample(std::string sample); returns an std::vector<int>, so at your cpp file you have to return the same type like this:
std::vector<int> BinaryCounter::addSample(std::string sample)
{
return oneCountColumns;
}
I was missing the std::vector in the .cpp file. This is what happens when I dust off the cobwebs to join AOC

Type '' could not be resolved, template type [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 2 years ago.
Improve this question
I am a bit rusty with programming and couldn't find a solution on the web.
I am creating a template class, and when using it I seem to be getting the error:
Type 'temp' could not be resolved
I have to tried to clean and rebuild, but it didn't help. Any advice is appreciated.
/*
* avlTREE.h
*
* Created on: May 1, 2016
* Author:
*/
#ifndef AVLTREE_H_
#define AVLTREE_H_
#include <cassert>
#include <functional>
class avlTreeException{};
class avlTreeExceptionInvalidInput : public avlTreeException{};
template <class temp>
class avlTREE{
public:
temp* ptr;
}
#endif /* AVLTREE_H_ */
Apart from the missing semicolon, there is nothing inherently wrong with your template class.
template <class temp>
class avlTREE{
public:
temp* ptr;
};
int main(){
avlTREE<int> foo;
}

C++ compiler thinks my constructor definition is a method [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 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'm getting the following errors:
C:\Users\James\cavewhere\dewalls\src\unit.cpp:6: error: C2511: 'dewalls::Unit::Unit(QString,dewalls::UnitType *)' : overloaded member function not found in 'dewalls::Unit'
C:\Users\James\cavewhere\dewalls\src\unit.cpp:9: error: C2550: 'dewalls::Unit::{ctor}' : constructor initializer lists are only allowed on constructor definitions
unit.h:
#ifndef UNIT_H
#define UNIT_H
class UnitType;
#include <QString>
namespace dewalls {
class Unit
{
public:
Unit(QString name, UnitType *type);
private:
QString _name;
UnitType *_type;
};
}
#endif // UNIT_H
unit.cpp:
#include "unit.h"
#include "unittype.h"
namespace dewalls {
Unit::Unit(QString name, UnitType *type) :
_name(name),
_type(type)
{
}
}
What for the love of god am I doing wrong?
Looks like UnitType should be in your namespace too
namespace dewalls {
class UnitType;
}

Return class type not recognized in c++ [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 have written a class:
CVerifObj.hpp:
#pragma once
#include <vector>
class VerifObj
{
private:
cv::Mat m_image;
PointVector m_plateContour;
std::string m_imageName;
public:
VerifObj(const fs::path& imgNameIn);
~VerifObj();
cv::Mat getImage() const;
std::string getImageName() const;
PointVector getPlateContour() const;
};
typedef std::vector< VerifObj > VerifObjVector;
That has implementation and that is used as a type of another function in another class that includes its header:
MyCls.hpp:
#pragma once
#include "CVerifObj.hpp"
class MyCls
{
public:
MyCls();
~MyCls();
static VerifObjVector foo(); // error is here
};
The problem I get is that it is not recognized:
/home/sop/proj/CMyCls.hpp:52:2: error: ‘VerifObjVector’ does not name a type
I have added it in the CMake file too. Why is this happening?
You haven't included the std::vector definition:
#include <vector>
You're probably including MyCls.hpp in CVerifObj.hpp, directly or indirectly, which leads to a circular include. This can cause issues (undefined types).
Remove circular includes by using forward declarations.

no default constructor exists for class (c++ classes) [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
#include<iostream>
#include<string>
using namespace std;
#ifndef TicTac_H
#define TicTac_H
class TicTac
{
public:
TicTac(int ,int);
void setpos(int);
void getpos(int);
void setpos2(int);
void getpos2(int);
bool takepos();
void setar(int&, int&);
void setarr();
void all(int,int);
void print();
int test();
private:
int p1;
int p2;
string tic[3][3] ;
string x;
string o;
int t1;
int t2;
bool ok;
};
#endif
**The compiler shown this message :
no default constructor exists for class "TicTac"
'TicTac' : no appropriate default constructor available
can anybody help me to fix this problem **
The error is surely not in that code, but in the code that includes that header and attempts to create an object of type TicTac without providing the two arguments that the constructor takes (two int). Other than that, the include guards should cover all the file (including the #include<...>) and you should never have a using directive (using namespace X) in a header.