In my gtk+ application i have following code:
G_DEFINE_TYPE(PicFile, pic_file, G_TYPE_OBJECT)
When i try to compile it i see error:
error:invalid application of sizeof to incomplete type 'PicFileClass'
Where PicFileClass -
typedef struct _PicFileFileClass PicFileClass;
struct _PicFileClass {
GObjectClass parent;
};
What's wrong?
Thank you.
In your first line you have _PicFileFileClass, while later it becomes _PicFileClass.
Related
I have my class Queue (declared in Queue.h and implemented in Queue.cpp) and the 'Node' struct defined in the Queue.h file, like this:
Queue.h
//...
typedef int TElem;
struct Node{
TElem data;
Node *next;
};
class Queue
{
private:
Node *head;
Node *tail;
public:
// ... some other methods
}
Then, in Queue.cpp
//...
Queue::Queue()
{
head = nullptr;
tail = nullptr;
}
These last 2 lines of code in my constructor produce 4 errors, two for each line:
'identifier "head" is undefined' / 'identifier "tail" is undefined' and "'head': undeclared identifier" / "'tail': undeclared identifier". Why is this and how can I solve this ? I have read answers to similar questions, yet none answered mine.
I am sorry for this, there was a problem with my files. I did something bad with the files when creating the project. The code ran just fine afterwards.
I wan to update this code to swift 4:
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
return rc;
}
But I get two errors:
Declaration of 'select' must be imported from module 'Darwin.POSIX.sys.time' before it is required
Implicit declaration of function 'select' is invalid in C99
How can I can fix this?
Add this near the top of your file:
#include <sys/time.h>
I'm using Eclipse and MinGW. I've got undefined reference to error to all that I write in h files, that I do include in cpp-file where main located. I create an empty project, and the same thing again (
main.cpp
#include <iostream>
#include "Stack.h"
using namespace std;
int main(){
Stack<int> stack(10);
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
stack.h
#ifndef STACK_H_
#define STACK_H_
template <class T>
class Stack{
private:
struct StackEl;
StackEl *top;
public:
Stack();
Stack(T el);
~Stack();
void Push(const T& el);
T Pop();
};
#endif /* STACK_H_ */
and stack.cpp inplements everything from stack.h
If I include not h-file, but cpp - all works. Help please!
I've got following errors
D:/Workspacee/Stack2/Debug/../src/Stack2.cpp:16: undefined reference to `Stack<int>::Stack(int)'
D:/Workspacee/Stack2/Debug/../src/Stack2.cpp:18: undefined reference to `Stack<int>::~Stack()'
D:/Workspacee/Stack2/Debug/../src/Stack2.cpp:18: undefined reference to `Stack<int>::~Stack()'
This is a linker error. I'm no Eclipse expert, but you have to tell it somehow to add Stack.o to the linking command.
If you include Stack.cpp instead of Stack.h, the implementations from the cpp-file get included into main.cpp by the preprocessor before compilation, so the linking stage has no unresolved references to outside functions.
My bad, that is becouse templates! When you use template, all code, including realization of functions, must be in header-file, or you have to write prototypes for every type you are going to use you template-functions with. I've forgot about that working with templates is not the same as with usual function :(
I am trying to write some code to optimize some Open GL functions for a program I'm writing, unfortunately, I am not exactly a C or C++ veteran, but that's partially why I'm doing this project!
So I'm creating a struct to handle 3x3 matrices and I am defining the struct as follows:
#ifndef MATRIX3BY3_H
#define MATRIX3BY3_H
struct Matrix3by3
{
float ix, jx, kx;
float iy, jy, ky;
float iz, jz, kz;
Matrix3by3() {}
Matrix3by3(const Matrix3by3 &matrix)
{
ix = matrix.ix;
jx = matrix.jx;
kx = matrix.kx;
iy = matrix.iy;
jy = matrix.jy;
ky = matrix.ky;
iz = matrix.iz;
jz = matrix.jz;
kz = matrix.kz;
}
Matrix3by3 (const float _ix, const float _jx, const float _kx,
const float _iy, const float _jy, const float _ky,
const float _iz, const float _jz, const float _kz) :
ix(_ix), jx(_jx), kx(_kx),
iy(_iy), jy(_jy), ky(_ky),
iy(_iz), jx(_jz), kz(_kz) {}
};
#endif
And I get the error (twice)
Expected specifier-qualifier-list
before 'Matrix3by3'
On the line of the first constructor. I have tried to look around for answers for this, and it seems that it has to do with the compiler not knowing that this is a type. So I have tried the following, I'll remove the innards for brevity:
typedef struct Matrix3by3 { ... };
struct Matrix3by3 { struct Matrix3by3() {} ... };
struct Matrix3by3 { ... } Matrix3by3;
typdef struct Matrix3by3;
struct Matrix3by3 { ... };
Which are all solutions that were suggested on blogs and articles that I saw for this error. I also saw that it may arise because of a circular dependency, but this file has no includes that include anything else, and I've even removed them just to be certain from time to time - no change.
I could write this in a objective-c class, I'm sure, but it will probably take a tiny bit more memory and cycles, and that's exactly what I'm trying to avoid. The only thing I can think of left is some compiler/project setting that I have set by default that precludes my using this type of structure. Entirely possible, as I'm learning the language/environment.
Can any one provide some help?
Thanks!
C does not support constructors or member functions of structs. There is no way you will get this to compile as C or Objective-C. You need to compile this as C++ or Objective-C++, at which point it will almost compile: you have an error in your 3rd constructor, in that you're attempting to initialize the members iy and jx multiple times. Once you fix those typos, it compiles just fine.
typedef struct { ... } Matrix3by3;
should work. It declares the anonymous struct as a type.
And use class instead of struct :)
What language/compiler are you translating your program with? I'd guess that you are trying to compile the code as C, while the language features you are trying to use are strictly C++-specific.
The error "Expected specifier-qualifier-list before 'Matrix3by3'" is a GCC-ism and it means that the token "Matrix3by3" is unknown. This is typically the case when you have a type that the compiler doesn't recognize, either because you mistyped it or because you forgot a header. In your case, it's because the type "Matrix3by3" really doesn't exist. You have two options:
Stop using Matrix3by3 directly and start using struct Matrix3by3 instead, as that's the actual type you defined.
Give your struct a typedef. It will look something like
typedef struct {
// fields here
} Matrix3by3
I've got a peculiar error writing some C++/CLI code. I'm trying to make a copy of a class which holds some data.
The class is defined as:
public ref class RawDataPacket
{
protected:
float* m_internalData;
public:
RawDataPacket(const float* newInternalData);
RawDataPacket(const RawDataPacket^ rdp);
RawDataPacket(RawDataPacket^ rdp);
RawDataPacket();
};
When I try and make use of the class as follows:
void SomeClass::SomeFunction( RawDataPacket^ rdp )
{
// Send a copy of the packet to anyone interested.
RawDataPacket^ rdp1 = gcnew RawDataPacket( rdp );
ForwardData( rdp1 );
}
I get:
error C2512: 'RawDataPacket' : no appropriate default constructor available
I thought that RawDataPacket(); had that covered? ..or am I missing something really obvious there?
[Edit] The body of RawDataPacket() looks like this:
RawDataPacket::RawDataPacket()
{
m_internalData = nullptr;
}
[Edit2] The full compiler output looks like this:
1>------ Build started: Project: MySoftware, Configuration: Debug Win32 ------
1>Compiling...
1>RawDataPacket.cpp
1>Controller.cpp
1>.\Controller.cpp(452) : error C2512: 'MySoftware::RawDataPacket' : no appropriate default constructor available
1>Build log was saved at "file://c:\Projects\Experiments\MySoftware\Debug\BuildLog.htm"
1>MySoftware - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
Got it! It occurred to me that I'd forward-declared the RawDataPacket class in the header of the Controller class.
I tried including the header in there and removing the forward declaration and it worked. So it turns out that despite forward-declaring the class I'd forgotten to include the header in Controller.cpp
That could have been a nasty one to find.. cheers for the help all!
use explicit before the constructor if you are having parameters for constructor.