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 Librtmp.dll in the debug folder where my exe is generated. The header and auxillary code files are available in my project and included as shown below.
Using this include.... i can use librtmp with intellisense.
extern "C" {
#include "libavcodec/avcodec.h"
#include "libavdevice/avdevice.h"
#include "libavfilter/avfilter.h"
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
#include "librtmp/rtmp.h"
}
Here is the code example that is being used.
RTMP *r;
char uri[]="rtmp://localhost:1935/live/desktop";
r = RTMP_Alloc();
RTMP_Init(r);
RTMP_SetupURL(r, (char*)uri);
RTMP_EnableWrite(r);
RTMP_Connect(r, NULL);
RTMP_ConnectStream(r,0);
VS2012
IntelliSense: argument of type "RTMP *" is incompatible with parameter of type "RTMP *"
This occurs at this point first. Then once again, for each follow r variable.
r = RTMP_Alloc();
Some reading has suggested using a typedef.
Understanding typedefs for function pointers in C
This lead to...
typedef (RTMP*)(RTMP* rtmp);
However, Visual Studio just laughed at me... shaking it's head wondering if i even knew what i was doing.
IntelliSense: declaration of a member with the same name as its class
Any clues or ideas would be useful.
Thank you.
UPDATE - COMPLETE CODE
extern "C" {
#include "libavcodec/avcodec.h"
#include "libavdevice/avdevice.h"
#include "libavfilter/avfilter.h"
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
}
#include "librtmp/rtmp.h"
class RTMP
{
RTMP()
{
}
~RTMP()
{
}
typedef (RTMP*)(RTMP* rtmp);
void RTMP::Run()
{
//Code
//Init RTMP code
RTMP *r;
char uri[]="rtmp://localhost:1935/live/desktop";
r = RTMP_Alloc();
RTMP_Init(r);
RTMP_SetupURL(r, (char*)uri);
RTMP_EnableWrite(r);
RTMP_Connect(r, NULL);
RTMP_ConnectStream(r,0);
}
};
EPIC FACE PALM
Deepest Apologies
My class is called RTMP
Thank you #vard
Related
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'm trying to use header files to transfer functions in a namespace on a separate file to another file, and it's returning the error
"Add" is not a member of "simple".
I simply want to know if it's possible to use forward function declarations rather than declaring the function every time in the header, which supposedly would keep copying the code for every .cpp that includes it.
Here's the basic outline for 1.cpp, 2.cpp and 3.h.
1.cpp
#include "stdafx.h"
// Check this header file for function declarations.
#include "3.h"
int main()
{
//Example of a single namespace.
std::cout << simple::add(3, 4);
return 0;
}
2.cpp
#include "stdafx.h"
namespace simple {
int simple::add(int x, int y) {
return x + y;
}
}
3.h
#ifndef NAMESPACES
#define NAMESPACES
namespace simple {
int simple::add(int, int);
}
#endif
Much appreciation to anyone who answers, and apologies if this has been asked before.
Figured out the issue, for any future viewers of this thread.
You don't use the prepending "simple::" on header declarations, or in the function itself, as I did.
Corrected code:
3.h
#ifndef NAMESPACES
#define NAMESPACES
//Header guards are important!
namespace simple {
int add(int, int);
}
#endif
2.cpp
#include "stdafx.h"
#include "3.h"
int simple::add(int x, int y) {
return x + y;
}
No changes are required to 1.cpp.
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 5 years ago.
Improve this question
I have the following code excerpt.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <fstream>
#include <string>
#include <array>
using namespace std;
int solver(int T)
{
/* read IA */
ifstream inputFile("IA [0;1.3077].txt");
vector<int> ia;
if (inputFile) {
int num;
while ( inputFile >> num) {
ia.push_back(num);
}
}
}
int main (void) {
solver(360);
}
But it gives me this error:
error: implicit instantiation of undefined template
'std::__1::vector<int, std::__1::allocator<int> >'
vector<int> ia;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iosfwd:200:29: note:
template is declared here
class _LIBCPP_TYPE_VIS_ONLY vector;
The goal is to read a txt file with integers per line without knowing how many lines there are in advance. I'm choosing a vector to hold the data because I don't want to initialize an integer array with a fixed size. Does anybody have any suggestions?
Also, I understand that the variable T is unused - I will use it after the .txt file is loaded.
You need to:
#include <vector>
You must alway include directly all the headers for the types you use.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 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 don't know what's wrong here ?
It's just running errors !!!
#include <iostream>
using namespace std;
int main()
{
cout << string("hello world");
return 0;
}
Read more about C++. So read first Programming -- Principles and Practice Using C++.
Then read C++ reference documentation, notably the one about std::string-s.
You need to #include <string>
You should enable all warnings when compiling. If using GCC, compile with g++ -Wall -g
You don't need that string before the actual string:
#include <iostream>
using namespace std;
int main()
{
cout << "hello world";
return 0;
}
Or, alternatively, if you're trying to store a string:
#include <string>
#include <iostream>
using namespace std;
int main()
{
string str = "hello world";
cout << str;
return 0;
}
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>
using namespace std;
{
class book
{
public:
set_book();
show_book();
private:
string title,author;
int pages,date;
};
}
In addition to the points made by other answers...
You have:
set_book();
show_book();
These are not valid member function declarations. They need, at the least, a return type.
void set_book();
void show_book();
Please add any input arguments needed by them.
You are missing includes (string), you should avoid using namespace std in a header.
And also, remove this extra scope :
using namespace std;
// { <------
class book
{
public:
set_book();
show_book();
private:
string title,author;
int pages,date;
};
// } <------
You have a bogus set of { and }.
Change to:
#include <iostream>
using namespace std; // this is a bad idea BTW
class book
{
// etc.
Also it'd be a good idea to #include <string> in case whoever includes your file does not include that; and if you don't actually use iostream then don't include it.
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
Question: I have delcared a class, then used in my main function, it throws undefined error. Then I added .h file, and it throws another error. My question is about to write .h in accordance with the .cpp class file. Here are details:
I have this class declated in ElevatorButton.cpp:
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class ElevatorButton
{
public:
int pressed = 0; // boolean
void myFunc(int param1)
{
cout << param1 << endl;
}
};
And then I have this file in ElevatorSimulation.cpp:
#include "stdafx.h"
#include <iostream>
#include <string>
#include "Header.h"
using namespace std;
int main()
{
ElevatorButton ElvBtn;
cout << ElvBtn.myFunc(1) << endl;
}
Compiling the code regularly throws error. I should declare header file as it seems. But in my header file, how should I manage the definition? I have read about .h file but still am confused. Here is my header.cpp:
#ifndef ElevatorButton_H
#define ElevatorButton_H
class ElevatorButton
{
public:
int pressed = 0; // boolean
public:
void myFunc(int param1){};
};
#endif
But it throws the following error with the Header.h:
1>ElevatorSimulation.cpp(14): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
You're getting that error because myFunc returns void, so
cout << ElvBtn.myFunc(1)
doesn't have a definition when the right hand side evaluates to void. If you want to print a value with cout, myFunc will have to return a type that can be passed into a stream.
The issue isn't with your class definition at all, it's in your main function.
Is it header.cpp? Because it should be header.h