Ambiguating new declaration of 'void visualizar()' [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 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?

Related

Getting a compilation error while using (<=>) [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 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?

unexpected compilation error in a function call (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 4 years ago.
Improve this question
I have a template function makeMatrix(), code is:
template<size_t N>
void makeMatrix(string dataFilePath, int adjcMatrix[N][N])
{
fstreamExtension fe("adj.txt", ios::in|ios::binary);
string s;
vector<int> temp;
int i = 0;
while(!fe.eof())
{
getline(fe, s);
temp = tokenizeToInt(s, ",\n")); //error: expected ';' before ')' token|
for(int j = 0; j < N; j++)
adjcMatrix[i][j] = temp[j];
i += 1;
}
}
fstreamExtension is a class I created and is included in program through header
#include "fstreamExtension.h", other included headers are iostream string and boost/tokenizer.hpp.
code for tokenizeToInt():
vector<int> tokenizeToInt(string& intString, const char* seperators)
{
vector<int> intValues;
boost::char_separator<char> delims(seperators);
boost::tokenizer<boost::char_separator<char>> tokens(intString, delims);
for (const auto& t : tokens) {
intValues.push_back(atoi(t.c_str()));
}
return intValues;
}
Why it is causing a compilation error in the makeMatrix(), the syntax seems correct, I didn't called it in main(), was compiling some other code then this error popped up when I started a build.
IDE : codeblocks 16.01, gcc.
You should listen to what the compiler tells you. Often the error is simpler than you think:
temp = tokenizeToInt(s, ",\n")); //error: expected ';' before ')' token|
An extra right-parenthesis. The compiler error means "I thought you were done with this command, why are you trying to close another parenthesis-pair?"

Unable to push_back to vector [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 7 years ago.
Improve this question
I have created an instance of the class however I am unable to push_back the name of the ship to the vector.
if (rows->_rows.size() != rows->rows_Size)
{
rows->_rows.push_back (ship->name); }
I get the following errors.
Error 1 error C2664: 'void std::vector<_Ty>::push_back(Berths &&)' : cannot convert parameter 1 from 'std::string' to 'Berths &&'
6 IntelliSense: no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=Berths, _Alloc=std::allocator]" matches the argument list
argument types are: (std::string)
object type is: std::vector>
The code for the class I am trying to add the data to is:
#pragma once
class Berths;
#include "Berths.h"
#include "Ship.h"
#include <iostream>
#include <vector>
class Rows { public: Rows(void); ~Rows(void);
std::vector<Berths> _rows; int rows_Size;
bool dock(Ship ship);
bool undock(Ship ship);
};
Rows::Rows(void)
{
rows_Size = 10;
}
Any ideas as to what is causing this?
Thanks
.size() is a member function of a vector. Hence you should use rows->_rows.size() instead. It's a common mistake we all make.

Understanding errors in printing a Linked list 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 9 years ago.
Improve this question
I have recently worked on C, but I have started to study C++. I had a homework in to create a program that would read texts and organize data out of the imputed text. This is the last part I have left, but I don't get what's wrong with my code. This part of the problem is pretty simple, but I still don't understand what my errors are. I got used to gcc compiler which wrote mostly segmentation fault, but g++ compiler errors are different. Any tips or hints on what to pay more attention while transferring from c to c++ would be really appreciated.
This is my output errors.
-bash-3.2$ g++ -o Printfunction Printfunction.cpp
Printfunction.cpp: In function 'void Printfunction(wordList*)':
Printfunction.cpp:43: error: cannot convert 'NumberList*' to 'Numberlist*' for argument '1' to 'std::string returnlist(Numberlist*)'
Printfunction.cpp: In function 'std::string returnlist(Numberlist*)':
Printfunction.cpp:56: error: invalid use of undefined type 'struct Numberlist'
Printfunction.cpp:10: error: forward declaration of 'struct Numberlist'
Printfunction.cpp:56: error: 'to_string' was not declared in this scope
Printfunction.cpp:57: error: invalid use of undefined type 'struct Numberlist'
Printfunction.cpp:10: error: forward declaration of 'struct Numberlist'
Can you please tell me what's wrong with my code?
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct NumberList
{
int line;
struct Numberlist *nextPtr;
};
struct wordList
{
string word;
int Count;
NumberList lines;
struct wordList *nextPtr;
};
void Printfunction(wordList *list);
string returnlist(Numberlist *list);
int main()
{
wordList something;
something.word = "SOMETHING";
something.Count = 55555;
something.nextPtr = NULL;
Printfunction(&something);
}
void Printfunction(wordList *list)
{
int i;
i=1;
cout<<"+----+----------------------------+-------+---------------------------------+"<<endl;
cout<<"|# | WORD | COUNT | LINES |"<<endl;
cout<<"+----+----------------------------+-------+---------------------------------+"<<endl;
while(list != NULL)
{
cout<<"|"<<left<<setw(4)<<i<<"|"<<left<<setw(28)<<list->word<<"|"<<left<<setw(7)<<list->Count<<"|"<<left<<setw(33)<<returnlist(&(list->lines))<<"|"<<endl;
cout<<"+----+----------------------------+-------+---------------------------------+"<<endl;
list = list->nextPtr;
i++;
}
}
string returnlist(Numberlist *list)
{
string final;
while(list != NULL)
{
final.append(", ");
final.append(to_string(list->line));
list = list->nextPtr;
}
final.append(".");
return final;
}
The problem is that sometimes you spell it NumberList, and sometimes you spell it Numberlist.
Any tips or hints on what to pay more attention
Case matters.

C++ compiling errors [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 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;