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 6 days ago.
Improve this question
New to C++ here, following outdated training videos...
Trying to compile this simple code, but getting the below error:
#include <iostream>
int main(){
auto result = (10 <=> 20) > 0;
std::cout << result << std::endl;
}
Error I get is:
prog.cc: In function 'int main()':
prog.cc:4:25: error: expected primary-expression before '>' token
4 | auto result = (10 <=> 20) > 0;
|
What am I doing wrong?
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 2 years ago.
Improve this question
I am new in C++ and i have a little error in this program "Hello world"
//ejemplo funciones definidas por el usuario
#include<iostream>
using namespace std;
int visualizar();
int main()
{
visualizar();
return 0;
}
void visualizar() //Here is the error
{
cout<<"Hola mundo guay\n";
}
Error:
C:\Users\lisan\OneDrive\Desktop\c++\EjemploFunciones.cpp In function 'void visualizar()':
15 17 C:\Users\lisan\OneDrive\Desktop\c++\EjemploFunciones.cpp [Error] ambiguating new declaration of 'void visualizar()'
6 5 C:\Users\lisan\OneDrive\Desktop\c++\EjemploFunciones.cpp [Note] old declaration 'int visualizar()'
What does this error mean? What caused it? How do I fix it?
In your prototype of visualizar, you declared it as
int visualizar();
However, when you defined it, you wrote
void visualizar() { ... }
Notice that the return types are different. Did you mean to use void throughout?
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 3 years ago.
Improve this question
Sorry for inconvenience, I don't know much about C++, i am facing this error while running on LINUX. Two errors in last two lines, and the error is the same. What am i doing wrong?
Thanks!
#define AOCL_ALIGNMENT 64
void *ptr = NULL;
posix_memalign(&ptr, AOCL_ALIGNMENT, 128);
free(ptr);
You can't call function outside of a scope in C/C++.
You have to call them from a function:
#define AOCL_ALIGNMENT 64
int main() {
void *ptr = NULL;
posix_memalign(&ptr, AOCL_ALIGNMENT, 128);
free(ptr);
}
You have to put your code into a function, it cannot run standalone:
#include <cstddef>
#define AOCL_ALIGNMENT 64
int main (void) {
void *ptr = NULL;
posix_memalign(&ptr, AOCL_ALIGNMENT, 128);
free(ptr);
}
Without the code being inside the main function, I am getting this errors then (speficially for Lundin):
$ g++ -O2 g.c -o g -Wall
g.c:5:15: error: expected constructor, destructor, or type conversion before ‘(’ token
posix_memalign(&ptr, AOCL_ALIGNMENT, 128);
^
g.c:7:5: error: expected constructor, destructor, or type conversion before ‘(’ token
free(ptr);
^
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 some code, it's quite large so I'll just create a snapshot of it here:
int l = 3;
vector<int> weights;
void changeWeights(int out){
for (int i = 0; i < weights.size(); i++){
int w = std::stoi(std::to_string(weights[i])) -
out*std::stoi(std::to_string(weights[i]));
if (w < -l){
w = -l;
} else if(w > l){
w = l;
}
weights.assign(i, w);
}
}
I get errors on both the 'stoi' and 'to_string' function calls in the form of
Main.cpp:35:21: error: ‘stoi’ is not a member of ‘std’
int w = std::stoi(std::to_string(weights[i])) -
^
Main.cpp:35:31: error: ‘to_string’ is not a member of ‘std’
int w = std::stoi(std::to_string(weights[i])) -
^
Main.cpp:36:17: error: ‘stoi’ is not a member of ‘std’
out*std::stoi(std::to_string(weights[i]));
^
Main.cpp:36:27: error: ‘to_string’ is not a member of ‘std’
out*std::stoi(std::to_string(weights[i]));
I have read some similar queries whereby the answer was to add in -std=c++11 or -std=c++0x when compiling - both these solutions did not work. Another solution suggested a bug in the compiler version but it's not the compiler I am using I do not think. I am using g++ (GCC) 5.0.0 20141005 (experimental) version on a 64x Apple Macbook Pro.
Usage of stoi() and to_string() in this part of code is pretty weird, and completely unnecessary. You can simply write
int w = weights[i] - out * weights[i];
To use std::stoi() and std::to_string() you need to have a proper
#include <string>
statement, and the c++11 language options set (see the links to the documentation reference above).
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 9 years ago.
Improve this question
First of all here is my C++ source:
#include <iostream>
using namespace std;
void number(int x){
cout << "Number is: " << x << endl;
}
int main(){
cin >> int x;
number(x);
return(0);
}
Upon compiling I get the following errors:
file.cpp: In function 'int main()':
file.cpp:9:9: error: expected primary-expressing before 'int'
file.cpp:9:9: error: expected ';' before 'int'
file.cpp:10:9: error: 'x' was not declared in this scope
I compile and run this successfully in CodeBlocks but under Ubuntu with gcc or g++ things fail.
Change
int main(){
cin >> int x;
to
int main(){
int x;
cin >> x;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
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.
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
Improve this question
I am getting the following errors:
softwarew.hh: In constructor ‘Software::Software(std::string, int)’:
softwarew.hh:26:45: error: class ‘Software’ does not have any field named ‘ptr’
softwarew.hh:28:7: error: ‘ptr’ was not declared in this scope
softwarew.hh: In destructor ‘Software::~Software()’:
softwarew.hh:40:6: error: ‘ptr’ was not declared in this scope
Can someone explain why I receive these errors?
The code that causes the errors:
Software(std::string name, int revision) : ptr(software_construct(name.c_str(), revision) ) {
if(!ptr) throw std::runtime_error("no software created");
}
~Software(){
if(ptr)
software_destruct(ptr);
}
private:
struct Software_s* ptr;
Your error says
"class Software does not have any field named ptr"
Given some suitable definitions of Software_s, software_construct, and software_destruct, making sure you put the field inside the class works:
#ifndef SOFTWAREw_INCLUDED
#defINE SOFTWAREw_INCLUDED
class Software{
Software(std::string name, int revision)
: ptr(software_construct(name.c_str(), revision)) {
if(!ptr)
throw std::runtime_error("no software created");
}
~Software(){
if(ptr)
software_destruct(ptr);
}
private:
struct Software_s* ptr;
};
#endif