Click here to Skip to main content
14,933,861 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I saw many, many solutions to that problem yet none of them seem to work in my case.

C++
<pre>#include <iostream>
#include <string>
#include <iostream>
#include <fstream>
#include <unordered_map>
using std::string;

Node* GetNewNode(string indeks, string atrybut, string oper, double wartosc, string indeks_NIE, string indeks_TAK, string komentarz);

class Node
{
public:
	std::string indeks;
	std::string atrybut;
	std::string oper;
	double wartosc;
	std::string ind_NIE;
	std::string ind_TAK;
	std::string komentarz;
	Node* left;
	Node* right;
};

int main()
{
	GetNewNode("a", "b", "c", 23.4, "d", "e", "f");
};

Node* GetNewNode(std::string indeks, std::string atrybut, std::string oper, double wartosc, std::string indeks_NIE, std::string indeks_TAK, std::string komentarz) {
	Node* newNode = new Node();
	newNode->indeks = indeks;
	newNode->atrybut = atrybut;
	newNode->oper = oper;
	newNode->wartosc = wartosc;
	newNode->ind_NIE = indeks_NIE;
	newNode->ind_TAK = indeks_TAK;
	newNode->komentarz = komentarz;
	newNode->left = newNode->right = NULL;
	return newNode;
};


This is just a part of a slightly bigger project, it however has left me scratching my head.

The errors are:

missing type specifier - int assumed. note c++ does not support default-int

times 2 for the line:
Node* GetNewNode(string indeks, string atrybut, string oper, double wartosc, string indeks_NIE, string indeks_TAK, string komentarz);

and times 2 for the line:
Node* GetNewNode(std::string indeks, std::string atrybut, std::string oper, double wartosc, std::string indeks_NIE, std::string indeks_TAK, std::string komentarz) {


The previous ones are my main problems, the others listed below arent there for the complete project.
'int Node':redefinition

Im working in Visual Studio

What I have tried:

checked about 2000 times if
#include <string>
was there,
watched a tutorial on youtube on creating BSTs while following them,
adding
return 0;
to the main function
Posted
Updated 28-Dec-20 9:39am
v2
Comments
KarstenK 29-Dec-20 5:12am
   
it is better to structure the code by putting a class into an own file with header and implementation. Than you only have to include the Node.h header at top of the main file.

You should put
C++
class Node;

just above the GetNewNode funciton declaration:

C++
#include <iostream>
#include <string>
#include <iostream>
#include <fstream>
#include <unordered_map>
using std::string;

class Node; //<==== add this line

Node* GetNewNode(string indeks, string atrybut, string oper, double wartosc, string indeks_NIE, string indeks_TAK, string komentarz);

class Node
{
public:
	std::string indeks;
	std::string atrybut;
//...


It is called class forward declaration, see, for instance: Class declaration - cppreference.com[^].
   
Comments
lelor 28-Dec-20 14:24pm
   
Thank You kind Sir, I think I've gone mad from not knowing a single solution... Have a great New Year!
CPallini 28-Dec-20 16:51pm
   
You are welcome.
Happy New Year!
Mr. Pallini gave you the correct information (remember to upvote his solution.) Another way you can deal with this is to rearrange the code so everything is declared before you use it. Here is how that can be done :
C++
#include <iostream>
#include <string>


class Node
{
public:
    std::string indeks;
    std::string atrybut;
    std::string oper;
    std::string ind_NIE;
    std::string ind_TAK;
    std::string komentarz;
    double wartosc        { 0 };
    Node* left            { nullptr };
    Node* right           { nullptr };
};


Node* GetNewNode(
                  std::string indeks
                , std::string atrybut
                , std::string oper
                , double wartosc
                , std::string indeks_NIE
                , std::string indeks_TAK
                , std::string komentarz
                )
{
    Node* newNode = new Node();
    newNode->indeks = indeks;
    newNode->atrybut = atrybut;
    newNode->oper = oper;
    newNode->wartosc = wartosc;
    newNode->ind_NIE = indeks_NIE;
    newNode->ind_TAK = indeks_TAK;
    newNode->komentarz = komentarz;
    return newNode;
};


int main()
{
    GetNewNode("a", "b", "c", 23.4, "d", "e", "f");
};
   
v2
Comments
CPallini 28-Dec-20 16:51pm
   
5.
KarstenK 29-Dec-20 5:13am
   
it is better to use files for every class.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900